OOP Quiz1 Practice
OOP Quiz1 Practice
Customer:
Getters and setters for attributes
Register
Login
Update profile
Place order
Order:
Confirm order/Cancel order
Payment method
Track/Update delivery status
Cart:
Add item to cart
Remove item from cart
View items in cart
Calculate total price
5.Relationships:
Each Order is associated with a single Customer.
Each Order can have multiple Product items.
Each Cart is associated with a single Customer.
Each Cart can have multiple Product items.
Customer interacts with Cart to add/remove items before placing an Order.
Customer places an Order, which contains information about the items
they've purchased.
OOP Q2
Write a java program for following scenerio:
Scenario: “Product Inventory System”
You have been tasked with developing a simple Product Inventory System for a
retail store. The system needs to manage product records including their unique
product ID, name, and quantity in stock. Additionally, the system should allow for
operations such as adding new products, updating quantities, and displaying
product details. Furthermore, there should be a mechanism to keep track of the
total number of products in the inventory. You are required to design a Java
program that performs the following:
Define a Product class with the following attributes: productID,
productName, and quantityInStock.
Implement multiple constructors for the Product class, including:
i. A default constructor that initializes the product with default values for
productID and productName, and sets quantityInStock to 0.
ii. A parameterized constructor that takes productID, productName, and
quantityInStock as parameters.
Introduce a static variable totalProducts to keep track of the total number of
products in the inventory.
Implement a static method getTotalProducts to retrieve the total number of
products in the inventory.
Solution:
public class Product {
private int productID;
private String productName;
private int quantityInStock;
private static int totalProducts = 0;
// Default constructor
public Product() {
this.productID = 0; // Default ID
this.productName = "Unknown"; // Default name
this.quantityInStock = 0; // Default quantity
totalProducts++;
}
// Parameterized constructor
public Product(int productID, String productName, int quantityInStock) {
this.productID = productID;
this.productName = productName;
this.quantityInStock = quantityInStock;
totalProducts++;
}
System.out.println("Product 2 Details:");
product2.displayProductDetails();
System.out.println();
System.out.println("Product 3 Details:");
product3.displayProductDetails();
System.out.println();