University of Sri Jayewardenepura - Object-Oriented Programming (OOP) Assignment
A comprehensive JavaFX application demonstrating core OOP principles, secure data handling, and modern UI design.
The Bookshop Discount Management System (BDMS) is a robust desktop application designed to solve a real-world business challenge: managing complex, multi-tiered discount structures in a retail environment. Built with Java 11, JavaFX 17, and Maven, this project serves as a practical demonstration of Object-Oriented Programming (OOP) concepts, software architecture, and secure coding practices.
Bookshops often struggle with manual discount calculations, leading to:
- Human Error: Mistakes in calculating bulk discounts or VIP rates.
- Inefficiency: Slow checkout processes.
- Inconsistency: Different discounts applied to similar customers.
- Security Risks: Unsecured data storage and weak authentication.
BDMS automates the entire process by:
- Dynamic Pricing: Automatically applying quantity-based bulk discounts.
- Customer Tiers: Distinguishing between Regular and VIP customers (VIPs get an extra 5% off).
- Secure Access: Role-based login (Manager vs. Cashier) with BCrypt password hashing.
- Data Integrity: Using file locking to prevent data corruption in CSV storage.
- BCrypt Hashing: User passwords are never stored in plain text. They are hashed using the industry-standard BCrypt algorithm.
- Input Sanitization: All user inputs are sanitized to prevent CSV Injection attacks.
- Concurrency Control: Implemented File Locking (
FileChannel.lock) to ensure safe concurrent writes to data files. - Strict Validation: Robust validation for customer data (e.g., phone number format).
- Cashier Portal: A responsive, grid-based POS interface with real-time product filtering.
- Auto-Search: Instant product and customer lookup without manual "Search" buttons.
- Live Cart: Dynamic shopping cart with real-time subtotal and discount updates.
- MVC Pattern: Separation of concerns using Model-View-Controller architecture.
- Service Layer: Business logic is encapsulated in
Serviceclasses (AuthService,ProductService,CustomerService). - File-Based Persistence: Lightweight CSV storage (
users.csv,products.csv,customers.csv) making the app portable and database-free.
This project is built upon the four pillars of Object-Oriented Programming:
Data is hidden within classes and accessed only through public methods, ensuring data integrity.
public class Product {
private String productId;
private double realPrice;
// Controlled access via getters and setters
public double getRealPrice() { return realPrice; }
public void setRealPrice(double price) {
if (price < 0) throw new IllegalArgumentException("Price cannot be negative");
this.realPrice = price;
}
}Specialized classes inherit behavior from generalized classes to promote code reuse.
// Base class
public abstract class Customer {
protected String name;
public abstract double getBaseDiscountRate();
}
// Derived class
public class VIPCustomer extends Customer {
@Override
public double getBaseDiscountRate() {
return 0.05; // VIPs get 5% base discount
}
}The system treats different objects (Regular vs. VIP) uniformly but they behave differently at runtime.
Customer customer = new VIPCustomer("John");
// The system doesn't need to know it's a VIP; it just asks for the rate.
double discount = total * customer.getBaseDiscountRate(); Complex logic is hidden behind simple interfaces. The FileHandler utility abstracts away the low-level details of file I/O, locking, and parsing.
// High-level usage
FileHandler.writeCsv("data/products.csv", lines);
// Low-level implementation (hidden)
// - Opens FileChannel
// - Acquires FileLock
// - Writes ByteBuffers
// - Handles IOExceptionsBookshopDiscountSystem/
βββ src/main/java/bookshop/
β βββ controllers/ # UI Logic (CashierController, AdminController)
β βββ model/ # Data Classes (Product, Customer, User)
β βββ service/ # Business Logic (AuthService, ProductService)
β βββ util/ # Helpers (FileHandler, PasswordMigrator)
βββ src/main/resources/
β βββ FXML/ # UI Layouts (.fxml)
β βββ Styles/ # CSS Styling
βββ data/ # CSV Data Storage
βββ docs/ # Documentation & Security Audit
βββ BookshopDiscountSystem-linux.sh # Linux executable script
βββ pom.xml # Maven Dependencies
- Java JDK 11 or higher.
- Maven 3.6+.
-
Clone the Repository:
git clone https://github.com/Chamath-Adithya/Bookshop-Discount-Management-System.git cd BookshopDiscountSystem -
Build the Project:
mvn clean install
-
Run the Application:
mvn javafx:run
- Admin/Manager: Creates new users.
- Worker/Cashier: Handles sales.
- (Note: Default users are stored in
data/users.csvwith hashed passwords)
- Cashier logs in.
- Searches for "Pen" (Price: Rs.100).
- Adds 10 Pens (Bulk discount applies -> Rs.80/each).
- Selects Customer "John" (VIP).
- System Calculation:
- Subtotal: 10 * 100 = Rs.1000
- Bulk Price: 10 * 80 = Rs.800
- VIP Discount: 5% of Rs.800 = Rs.40
- Final Total: Rs.760
- Malicious user tries to edit
customers.csvto inject a spreadsheet formula (=cmd|...). - System Defense: The application detects the special character and sanitizes the input by prepending a
', rendering the formula harmless.
- Chamath-Adithya - Lead Developer, Core Models & Project Foundation
- yasaruhashen - Customer Hierarchy & Service
- prabandisathsarani080-ai - User Roles & Data Management Services
- IOICybErIOI - Main Application & Billing Logic
- kaveesha-tharindi5 - Validation, Exceptions & Testing
This project was developed for the Object-Oriented Programming Module at the University of Sri Jayewardenepura.
- Linux: Run
./BookshopDiscountSystem-linux.sh - Windows: Run
target/BookshopDiscountSystem.exe
To generate the .exe file for Windows, run the following command:
MAVEN_OPTS="--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED" mvn clean packageEnsure Java 11+ is installed.