Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Assignment One: Arrays and Classes

Solve the following question in groups of two (Maximum).

Objective: Develop a system to manage a store's inventory.

Classes:
Product:
Private members: - String name
- double price
- int quantity

Public methods: + Constructors (default and with parameters)


+ Getters and setters for all private members
+ A method to calculate the total cost of all
items in stock (price * quantity)
Inventory:
Private members:
- Product[] products: Array to store Product objects

Public methods:
+ Constructor to initialize the products array
+ A method to add a new product
+ Methods to remove a product
(by index or by name, use overloading)
+ A method to display the entire inventory
(name, price, quantity)
+ A method to calculate the total value of all products in
stock (sum of each product's total cost)

Requirements:

* Implement the Product and Inventory classes with the specified


members and methods.

* In the Inventory class, ensure proper handling of potential issues


like exceeding the product limit (if using a fixed-size array) or
trying to remove a non-existent product.

* Create a main class (e.g., InventoryManagement) with a main method


to demonstrate the functionalities of the Inventory class.

* In the main method:


# Create an Inventory object.
# Add a few sample products using the add method.
# Remove a product and display the updated inventory.
# Display the total value of all products in stock.

You might also like