0% found this document useful (0 votes)
15 views1 page

Static - Inventory System - Task

Uploaded by

swapnilavate2011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Static - Inventory System - Task

Uploaded by

swapnilavate2011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

TheKiranAcademy

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:

1. Create a class named "InventoryItem."

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 "itemName" to store the name of the item.

- 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.

- A method named "removeFromInventory" that takes an integer as a parameter and subtracts it


from the item's quantity while also decrementing the "totalItems" variable.

3. In the "Main" class, create instances of the "InventoryItem" class and perform the following
operations:

- Create multiple inventory items.

- 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.

You might also like