Static - inventory system - Task
Static - inventory system - Task
Problem Statement:
Create a Java program that simulates a basic inventory system for a store using a `static` variable to
keep track of the total number of items in stock.
Requirements:
2. Inside the "InventoryItem" class, define the following attributes and methods:
- A `static` variable named "totalItems" to keep track of the total number of items in stock.
- An instance variable named "quantity" to store the quantity of the item in stock.
- A constructor that initializes the item's name and quantity when an object is created.
- A `static` method named "getTotalItems" that returns the total number of items in stock.
- A method named "addToInventory" that takes an integer as a parameter and adds it to the item's
quantity while also incrementing the "totalItems" variable.
3. In the "Main" class, create instances of the "InventoryItem" class and perform the following
operations:
- Add items to the inventory and update the total items in stock.
- Remove items from the inventory and update the total items in stock.
- Display the total number of items in stock using the `getTotalItems` method.
Ensure that your Java program effectively demonstrates the use of the `static` variable to keep track
of the total number of items in stock and allows for adding and removing items from the
inventory.ults.