0% found this document useful (0 votes)
10 views15 pages

Prabhjot Kaur

The Bookstore Management System is an object-oriented Java application that simulates bookstore operations, focusing on inventory management and customer interactions. It features inventory tracking, order placement with discounts, and administrative inventory management, utilizing principles of encapsulation, inheritance, and polymorphism. The document outlines the design, key classes, and methods, along with testing use cases and challenges encountered during development.

Uploaded by

eontrack.yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Prabhjot Kaur

The Bookstore Management System is an object-oriented Java application that simulates bookstore operations, focusing on inventory management and customer interactions. It features inventory tracking, order placement with discounts, and administrative inventory management, utilizing principles of encapsulation, inheritance, and polymorphism. The document outlines the design, key classes, and methods, along with testing use cases and challenges encountered during development.

Uploaded by

eontrack.yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Bookstore Management System

Object-Oriented Java Programming for a Business Domain Simulation

Course Code: IN2343-G3


Student Name: Prabhjot Kaur
Student ID: 202302650
Table of Contents

1. Problem Description

2. Design

o 2.1 Class Diagram (UML)

3. Code Explanation

o 3.1 Key Classes and Methods

o 3.2 Object-Oriented Principles in Use

4. Testing

o 4.1 Use Case 1: Purchasing a Book

o 4.2 Use Case 2: Viewing Inventory

5. Challenges and Solutions


1. Problem Description

The Bookstore Management System models the operations of a bookstore, focusing on


inventory management and customer interactions. Customers can purchase physical or digital
books, while administrators can monitor and manage inventory. Key features include:

 Inventory tracking for both physical books and eBooks.

 Customer order placement with bulk purchase discounts.

 An administrator's ability to view current inventory statistics.

This project implements Object-Oriented (OO) principles such as inheritance, encapsulation, and
polymorphism, providing modular and reusable code for a business simulation.

2. Design

2.1 Class Diagram (UML)

Diagram
The design highlights:

 Encapsulation: Private fields with controlled access via public methods.

 Inheritance: eBooks extending the Book class.

 Polymorphism: Overriding methods for customized behavior.

3. Code Explanation

3.1 Key Classes and Methods

Book Class

// Book.java

// Represents a book in the bookstore

public class Book {


private String title;

private String author;

private double price;

private int stock;

public Book(String title, String author, double price, int stock) {

this.title = title;

this.author = author;

this.price = price;

this.stock = stock;

public String getTitle() {

return title;

public double getPrice() {

return price;

public int getStock() {

return stock;

}
public void reduceStock(int quantity) {

if (quantity > 0 && quantity <= stock) {

stock -= quantity;

} else {

System.out.println("Invalid quantity or insufficient stock for " + title);

public String getDetails() {

return "Title: " + title + ", Author: " + author + ", Price: $" + price + ", Stock: " + stock;

 Represents a book in the inventory.

 Implements encapsulation using private fields and public getter methods.

 The reduceStock(int quantity) method ensures controlled stock updates.

EBook Class

// EBook.java

// Represents an eBook, extending the Book class

public class EBook extends Book {

private double fileSizeMB;


public EBook(String title, String author, double price, double fileSizeMB) {

super(title, author, price, Integer.MAX_VALUE); // Unlimited stock for eBooks

this.fileSizeMB = fileSizeMB;

@Override

public String getDetails() {

return super.getDetails() + ", File Size: " + fileSizeMB + "MB (eBook)";

 Extends the Book class to represent digital books.

 Overrides getDetails() to include file size information.

Customer Class

// Customer.java

// Represents a customer who can place orders

import java.util.ArrayList;

import java.util.List;

public class Customer {

private String name;

private List<Order> orders;


public Customer(String name) {

this.name = name;

this.orders = new ArrayList<>();

public void placeOrder(Book book, int quantity) {

if (book.getStock() >= quantity) {

double totalPrice = book.getPrice() * quantity;

// Apply a discount for bulk purchases (5 or more books)

if (quantity >= 5) {

totalPrice *= 0.9; // 10% discount

System.out.println("Bulk discount applied! New price: $" + totalPrice);

Order order = new Order(book, quantity, totalPrice);

orders.add(order);

book.reduceStock(quantity);

System.out.println("Order placed: " + quantity + " copy(ies) of " + book.getTitle());

} else {

System.out.println("Order failed: Not enough stock or invalid quantity.");

}
public void viewOrderHistory() {

System.out.println("Order History for " + name + ":");

if (orders.isEmpty()) {

System.out.println("No orders placed yet.");

} else {

for (Order order : orders) {

System.out.println(order.getOrderDetails());

 Represents a customer who can place orders.

 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

// Represents an order placed by a customer

public class Order {

private Book book;

private int quantity;


private double totalPrice;

public Order(Book book, int quantity, double totalPrice) {

this.book = book;

this.quantity = quantity;

this.totalPrice = totalPrice;

public String getOrderDetails() {

return "Book: " + book.getTitle() + ", Quantity: " + quantity + ", Total Price: $" + totalPrice;

 Represents an order placed by a customer.

 Stores the book details, quantity, and total price.

Administrator Class

// Administrator.java

// Represents an administrator who manages the inventory

import java.util.List;

public class Administrator {

public void viewInventory(List<Book> books) {

System.out.println("Inventory Details:");
for (Book book : books) {

System.out.println(book.getDetails());

 Allows administrators to view inventory.

 The viewInventory(List<Book> books) method iterates through the inventory and


displays book details.

Main Class

// Main.java

// The main class to demonstrate the use cases

import java.util.ArrayList;

import java.util.List;

public class Main {

public static void main(String[] args) {

// Create sample books

Book book1 = new Book("Java Programming", "Daniel Liang", 50.0, 10);

Book book2 = new Book("Effective Java", "Joshua Bloch", 45.0, 5);

EBook ebook1 = new EBook("Clean Code", "Robert C. Martin", 30.0, 1.5);

// Create a list to represent the bookstore inventory


List<Book> inventory = new ArrayList<>();

inventory.add(book1);

inventory.add(book2);

inventory.add(ebook1);

// Use Case 1: Customer purchasing books

Customer customer = new Customer("Alice");

System.out.println("\n--- Customer Use Case: Purchasing Books ---");

customer.placeOrder(book1, 2); // Alice buys 2 copies of Java Programming

customer.placeOrder(book2, 6); // Attempt to buy more than available stock

customer.placeOrder(book2, 5); // Bulk discount applied

customer.placeOrder(ebook1, 1); // eBook purchase

// View customer's order history

customer.viewOrderHistory();

// Use Case 2: Administrator viewing inventory

Administrator admin = new Administrator();

System.out.println("\n--- Administrator Use Case: Viewing Inventory ---");

admin.viewInventory(inventory);

}
 Demonstrates the system's use cases, including customer interactions and administrative
tasks.

3.2 Object-Oriented Principles in Use

 Encapsulation: Private fields with public getters/setters in all classes.

 Inheritance: EBook class extends the Book class.

 Polymorphism: Overridden getDetails() method in EBook class.

 Abstraction: Classes like Administrator abstract high-level operations such as viewing


inventory.

4. Testing

4.1 Use Case 1: Purchasing a Book

Input

 Customer: Alice

 Book: "Java Programming"

 Quantity: 2

Output

 Stock reduced, and an order created. Bulk discount applied for orders of 5 or more.

4.2 Use Case 2: Viewing Inventory

Input

 Administrator requests inventory details.


Output

 Displays all books with details, including remaining stock.

Screenshot

5. Challenges and Solutions

1. Stock Availability Validation

o Challenge: Orders were processed even when stock was insufficient.

o Solution: Added a conditional check in the placeOrder method to validate stock


before creating an order.

2. Encapsulation Enforcement

o Challenge: Direct access to fields like stock led to unintentional changes.

o Solution: Made fields private and introduced controlled methods like


reduceStock() for stock updates.
3. Class Interactions

o Challenge: Establishing meaningful relationships between Customer, Order, and


Book classes.

o Solution: Designed the Customer class to maintain an order history, linking each
order to a book instance.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy