[go: up one dir, main page]

0% found this document useful (0 votes)
17 views8 pages

OOP Quiz1 Practice

The document outlines the design and implementation of an Online Shopping System and a Product Inventory System. It details the potential objects, classes, attributes, methods, and relationships for the online shopping scenario, including products, customers, orders, and carts. Additionally, it provides a Java program for managing product records in an inventory, including constructors, static methods, and product details display.

Uploaded by

spartaking960
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)
17 views8 pages

OOP Quiz1 Practice

The document outlines the design and implementation of an Online Shopping System and a Product Inventory System. It details the potential objects, classes, attributes, methods, and relationships for the online shopping scenario, including products, customers, orders, and carts. Additionally, it provides a Java program for managing product records in an inventory, including constructors, static methods, and product details display.

Uploaded by

spartaking960
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/ 8

OOP Q1

Answer questions based on following scenario


“Online Shopping System”
Imagine you are asked to develop a simple online shopping system. The system
needs to keep track of products, customers and other order issuing activities
regadings cart status and orders information (Customer, Items,Total price, Order
date, Delivery address, payment information). Each product has specific details like
product #, poduct name, description and in stock/out stock. Customer have
information such as name, contact details, delivery address and a unique
membership ID. The online store wants to keep track of which products are
shopped by customer, update status of order being delivered to customer and cart
information of each customer profile. You are required to analyse the scenario and
do the following:
1. List the potential objects in this scenario.
2. define a corresponding class
3. Specify the attributes (data members) that each class should have.
4. For each class, specify the methods (functions) that should be associated
with them
5. Consider the relationships between the classes. How are objects of one
class related to objects of another class?
Solution:
1. Potential Objects:
 Product
 Customer
 Order
 Cart
2. Corresponding Classes:
 Product
 Customer
 Order
 Cart
3. Attributes:
Product:
 Product ID
 Product name
 Description
 Stock status (in stock/out of stock)
 Price
Customer:
 Name
 Contact details
 Delivery address
 Membership ID
Order:
 Order ID
 Customer (reference to Customer object)
 Items (list of Product objects)
 Total price
 Order date
 Delivery address
 Payment information
Cart:
 Customer (reference to Customer object)
 Items (list of Product objects)
4. Methods:
Product:
 Getters and setters for attributes
 Add product
 Update product details
 Remove product
 View product details

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++;
}

// Getter for totalProducts


public static int getTotalProducts() {
return totalProducts;
}

// Getter and Setter methods for productID, productName, and quantityInStock


public int getProductID() {
return productID;
}

public void setProductID(int productID) {


this.productID = productID;
}

public String getProductName() {


return productName;
}

public void setProductName(String productName) {


this.productName = productName;
}

public int getQuantityInStock() {


return quantityInStock;
}

public void setQuantityInStock(int quantityInStock) {


this.quantityInStock = quantityInStock;
}

// Method to display product details


public void displayProductDetails() {
System.out.println("Product ID: " + productID);
System.out.println("Product Name: " + productName);
System.out.println("Quantity in Stock: " + quantityInStock);
}

public static void main(String[] args) {


// Creating some sample products
Product product1 = new Product();
Product product2 = new Product(101, "Laptop", 10);
Product product3 = new Product(102, "Smartphone", 20);

// Displaying product details


System.out.println("Product 1 Details:");
product1.displayProductDetails();
System.out.println();

System.out.println("Product 2 Details:");
product2.displayProductDetails();
System.out.println();

System.out.println("Product 3 Details:");
product3.displayProductDetails();
System.out.println();

// Getting the total number of products


System.out.println("Total number of products: " + Product.getTotalProducts());
}
}

You might also like