Oop Assignment 2
Oop Assignment 2
Oop Assignment 2
Assessor’s
Feedback:
Assessor’s Date:
Signature:
TASK: Scenario: “Product Inventory System”
You are developing a simple Product Inventory System for a retail store. Each product has a unique
product code, a name, a price, and a quantity in stock. The system should be able to perform
operations like updating the stock quantity, displaying product details, and calculating the total value
of the inventory. Additionally, there should be a mechanism to track the total number of products in
the inventory.
1. Define a Product class with the following attributes: productCode, productName, price, and
quantityInStock.
2. Implement constructors with overloading properties for the Product class.
3. Implement multiple methods with overloading for the Product class.
Implement Static Variables and Functions to keep record of total products.
ANSWER:
Attributes of the product class:
o productCode
o productName
o price
o quantityInStock
Constructors with overloading properties for the Product class:
There are two constructors provided:
o One constructor accepts parameters for all attributes (productCode, productName, price,
quantityInStock).
o Another constructor accepts parameters for all attributes except quantityInStock, initializing
it to 0 by default.
Multiple methods with overloading for the Product class:
o updateStock(int quantity): Updates the stock quantity of the product.
o displayProductDetails(): Displays the details of the product including productCode,
productName, price, and quantityInStock.
o calculateInventoryValue(): Calculates and returns the total value of the inventory for the
product (price * quantityInStock).
o getTotalProducts(): Static method that returns the total number of products recorded.
o Getter methods for individual attributes (getProductCode(), getProductName(), getPrice(),
getQuantityInStock()): Provide access to individual attributes of the product.
Static Variables and Functions to keep a record of total products:
o totalProducts is a static variable that keeps track of the total number of products in the
inventory system.
o getTotalProducts() is a static method that retrieves the total number of products recorded.
o Source code of the given Scenario:
o Product Class:
o
o Main Class:
o