Prabhjot Kaur
Prabhjot Kaur
1. Problem Description
2. Design
3. Code Explanation
4. Testing
This project implements Object-Oriented (OO) principles such as inheritance, encapsulation, and
polymorphism, providing modular and reusable code for a business simulation.
2. Design
Diagram
The design highlights:
3. Code Explanation
Book Class
// Book.java
this.title = title;
this.author = author;
this.price = price;
this.stock = stock;
return title;
return price;
return stock;
}
public void reduceStock(int quantity) {
stock -= quantity;
} else {
return "Title: " + title + ", Author: " + author + ", Price: $" + price + ", Stock: " + stock;
EBook Class
// EBook.java
this.fileSizeMB = fileSizeMB;
@Override
Customer Class
// Customer.java
import java.util.ArrayList;
import java.util.List;
this.name = name;
if (quantity >= 5) {
orders.add(order);
book.reduceStock(quantity);
} else {
}
public void viewOrderHistory() {
if (orders.isEmpty()) {
} else {
System.out.println(order.getOrderDetails());
The placeOrder(Book book, int quantity) method validates stock availability, calculates
total price, and applies a bulk discount for orders of 5 or more books.
The viewOrderHistory() method displays all past orders for the customer.
Order Class
// Order.java
this.book = book;
this.quantity = quantity;
this.totalPrice = totalPrice;
return "Book: " + book.getTitle() + ", Quantity: " + quantity + ", Total Price: $" + totalPrice;
Administrator Class
// Administrator.java
import java.util.List;
System.out.println("Inventory Details:");
for (Book book : books) {
System.out.println(book.getDetails());
Main Class
// Main.java
import java.util.ArrayList;
import java.util.List;
inventory.add(book1);
inventory.add(book2);
inventory.add(ebook1);
customer.viewOrderHistory();
admin.viewInventory(inventory);
}
Demonstrates the system's use cases, including customer interactions and administrative
tasks.
4. Testing
Input
Customer: Alice
Quantity: 2
Output
Stock reduced, and an order created. Bulk discount applied for orders of 5 or more.
Input
Screenshot
2. Encapsulation Enforcement
o Solution: Designed the Customer class to maintain an order history, linking each
order to a book instance.