Java Objects and Classes Independent Practice
Learning objective: By the end of this lesson, students will be able to write a Java program that demonstrate their conceptual understanding of packages, classes, objects, instance and static members, and constructors.
Online store inventory
You are hired to create a simple program to manage the inventory of an online store. The store sells multiple products, each with a unique name, price, and quantity. Additionally, the store keeps track of the total number of products in stock (shared across all products).
Exercise requirements
- Create a package
com.store.inventorycontaining aProductclass. - The
Productclass should have:- The following instance variables:
String namedouble priceint quantity
- The following
staticvariable:int totalProducts
- A default constructor that initializes
nameto"Unknown",priceto0.0, andquantityto0. - A parameterized constructor that initializes all three instance variables and increments the static
totalProductsby 1. - A method to display product details:
void displayDetails().
- The following instance variables:
- Write a
Mainclass in thecom.store.apppackage to:- Instantiate multiple
Productobjects. - Display details for each product and the total number of products.
- Instantiate multiple