Skip to content

Aniket3434/CSC8404-Advanced-Programming-in-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PC Retailor Order Management System - CSC8404

Newcastle University | MSc Advanced Computer Science
Module: Advanced Programming in Java (CSC8404)

Java JUnit IntelliJ IDEA

πŸ“‹ Overview

PcRetailor is a comprehensive order management system for a PC retail business that allows customers to purchase either preset PC models from manufacturers or create custom configurations. The system demonstrates advanced Java programming concepts including object-oriented design, immutability patterns, defensive programming, and comprehensive unit testing.

🎯 Project Objectives

This coursework demonstrates mastery of:

  • Object-Oriented Design: Interface-based architecture with polymorphism
  • Immutability Patterns: Immutable classes for PresetModel, Customer, CreditCard, and Order
  • Defensive Programming: Input validation, defensive copying, and encapsulation
  • Design Patterns: Factory pattern, interface segregation
  • SOLID Principles: Single responsibility, open/closed, Liskov substitution
  • Comprehensive Testing: JUnit 5 test suite with 100+ test cases
  • Clean Code: Proper documentation, naming conventions, and code organization

πŸ—οΈ System Architecture

PcRetailor System
β”œβ”€β”€ Model Layer (PC Configurations)
β”‚   β”œβ”€β”€ PCModel (Interface)
β”‚   β”œβ”€β”€ PresetModel (Immutable - Third-party PCs)
β”‚   └── CustomModel (Mutable - Customer-built PCs)
β”œβ”€β”€ Customer Layer
β”‚   └── Customer (Immutable customer entity)
β”œβ”€β”€ Order Layer
β”‚   β”œβ”€β”€ Order (Customer orders with state management)
β”‚   β”œβ”€β”€ OrderStatus (Enum: PLACED, FULFILLED, CANCELLED)
β”‚   β”œβ”€β”€ CreditCard (Immutable payment information)
β”‚   └── CreditCardRegistry (Singleton for card validation)
└── System Layer
    β”œβ”€β”€ OrderSystem (Interface)
    └── OrderSystemImpl (Core business logic)

✨ Key Features

1. Dual PC Model Support

  • Preset Models: Pre-configured PCs from manufacturers (Dell, HP, Lenovo, etc.)
  • Custom Models: User-built configurations with add/remove parts functionality

2. Order Management

  • Place orders with multiple PC models
  • Order state transitions: PLACED β†’ FULFILLED or PLACED β†’ CANCELLED
  • Credit card validation with expiry date checking
  • Order tracking by customer and date

3. Business Analytics

  • Largest Customer: Track customer with highest order value
  • Most Ordered Model: Identify best-selling PC configurations
  • Most Ordered Part: Analyze popular components across all orders

4. Robust Validation

  • Credit card number format validation (16 digits)
  • Expiry date verification
  • Null and empty input checks across all operations
  • State-based operation restrictions (e.g., cannot cancel fulfilled orders)

πŸ› οΈ Technology Stack

Component Technology
Language Java 17+
Build System IntelliJ IDEA Project
Testing Framework JUnit 5 (Jupiter)
Design Patterns Factory, Singleton, Strategy
Version Control Git

πŸ“Š Class Descriptions

Core Classes

PCModel (Interface)

Defines the contract for all PC models in the system.

public interface PCModel {
    String getName();
    List<String> getParts();
}

PresetModel (Immutable)

Represents manufacturer-supplied PC configurations that cannot be modified after creation.

  • Key Features: Final fields, defensive copying, factory method pattern
  • Equality: Based on manufacturer + model name
  • Example: PresetModel.valueOf("Dell", "XPS-15", List.of("i7", "16GB RAM", "512GB SSD"))

CustomModel (Mutable with Encapsulation)

Allows customers to build personalized PC configurations.

  • Key Features: Add/remove parts, defensive copying on access
  • Mutability: Controlled through addPart() and removePart() methods
  • Example: Build a gaming PC step-by-step with custom components

Customer (Immutable)

Represents a customer in the system.

  • Fields: First name, last name
  • Validation: Non-null, non-empty names
  • Equality: Based on full name

Order

Represents a customer order with lifecycle management.

  • States: PLACED, FULFILLED, CANCELLED
  • Immutable Fields: Customer, models, credit card, order date
  • Mutable Field: Order status (controlled state transitions)
  • Defensive Copying: Order date returned as new instance

CreditCard (Immutable)

Secure payment information storage.

  • Validation: 16-digit card number, future expiry date
  • Security: Defensive copying of Date objects
  • Features: Expiry validation method

OrderSystemImpl

Core business logic implementation managing all orders.

  • Order placement with credit card validation
  • Order fulfillment tracking
  • Order cancellation with state checks
  • Analytics: largest customer, popular models/parts

πŸš€ How to Run

Prerequisites

Java Development Kit (JDK) 17 or higher
IntelliJ IDEA (recommended) or any Java IDE
JUnit 5 library (included in project)

Setup and Execution

1. Clone/Download the Repository

# Clone the repository (once uploaded to GitHub)
git clone https://github.com/Aniket3434/pc-retailor-java.git
cd pc-retailor-java

2. Open in IntelliJ IDEA

File β†’ Open β†’ Select PcRetailor folder
Wait for project indexing to complete

3. Compile the Project

Build β†’ Build Project
Or use: Ctrl+F9 (Windows/Linux) / Cmd+F9 (Mac)

4. Run Tests

# Run all tests
Right-click on 'Test' folder β†’ Run 'All Tests'

# Run specific test class
Navigate to Test/PcRetailor/System/OrderSystemImplTest.java
Right-click β†’ Run 'OrderSystemImplTest'

5. Run the Main Program (if applicable)

# The system is designed as a library/framework
# Interact with it through the OrderSystem interface

# Example usage (in a main class):
OrderSystem system = new OrderSystemImpl();
Customer customer = new Customer("John", "Doe");
PCModel model = new PresetModel("Dell", "XPS-15", 
    List.of("Intel i7", "16GB RAM", "512GB SSD"));
CreditCard card = new CreditCard("1234567812345678", 
    new Date(2026, 12, 31), "John Doe");

Order order = system.placeOrder(List.of(model), customer, "1234567812345678");

πŸ“ˆ Testing Strategy

Comprehensive Test Coverage

Test Class Focus Area Key Tests
CustomerTest Customer validation Name validation, equality, immutability
PresetModelTest Preset PC models Immutability, factory pattern, equality
CustomModelTest Custom PC building Add/remove parts, defensive copying
CreditCardTest Payment validation Card format, expiry validation
CreditCardRegistryTest Card management Registration, retrieval, singleton
OrderTest Order lifecycle State transitions, cancellation rules
OrderSystemImplTest Business logic Order placement, fulfillment, analytics

Test Statistics

  • Total Test Classes: 7
  • Test Coverage: All public methods tested
  • Edge Cases: Null inputs, empty collections, invalid states
  • Validation Tests: Comprehensive exception testing

Running Tests

# Run all tests with Maven (if configured)
mvn test

# Or in IntelliJ
Right-click Test folder β†’ Run 'All Tests'

πŸŽ“ Key Java Concepts Demonstrated

1. Immutability

public final class PresetModel implements PCModel {
    private final String manufacturer;
    private final String name;
    private final List<String> parts;
    
    public PresetModel(String manufacturer, String name, List<String> parts) {
        this.parts = List.copyOf(parts); // Immutable copy
    }
}

2. Defensive Copying

public Date getOrderDate() {
    return new Date(orderDate.getTime()); // Return copy, not reference
}

3. Factory Pattern

public static PresetModel valueOf(String manufacturer, String name, List<String> parts) {
    return new PresetModel(manufacturer, name, parts);
}

4. State Management

public void cancel() {
    if (status == OrderStatus.FULFILLED) {
        throw new IllegalStateException("Cannot cancel fulfilled order");
    }
    status = OrderStatus.CANCELLED;
}

5. Encapsulation with Validation

public void addPart(String part) {
    if (part == null || part.isEmpty()) {
        throw new IllegalArgumentException("Part cannot be null or empty");
    }
    parts.add(part);
}

πŸ“„ Project Structure

PcRetailor/
β”œβ”€β”€ src/
β”‚   └── PcRetailor/
β”‚       β”œβ”€β”€ Customer/
β”‚       β”‚   └── Customer.java
β”‚       β”œβ”€β”€ Model/
β”‚       β”‚   β”œβ”€β”€ PCModel.java (Interface)
β”‚       β”‚   β”œβ”€β”€ PresetModel.java
β”‚       β”‚   └── CustomModel.java
β”‚       β”œβ”€β”€ Order/
β”‚       β”‚   β”œβ”€β”€ Order.java
β”‚       β”‚   β”œβ”€β”€ OrderStatus.java
β”‚       β”‚   β”œβ”€β”€ CreditCard.java
β”‚       β”‚   └── CreditCardRegistry.java
β”‚       └── System/
β”‚           β”œβ”€β”€ OrderSystem.java (Interface)
β”‚           └── OrderSystemImpl.java
β”œβ”€β”€ Test/
β”‚   └── PcRetailor/
β”‚       β”œβ”€β”€ Customer/
β”‚       β”‚   └── CustomerTest.java
β”‚       β”œβ”€β”€ Model/
β”‚       β”‚   β”œβ”€β”€ PresetModelTest.java
β”‚       β”‚   └── CustomModelTest.java
β”‚       β”œβ”€β”€ Order/
β”‚       β”‚   β”œβ”€β”€ OrderTest.java
β”‚       β”‚   β”œβ”€β”€ CreditCardTest.java
β”‚       β”‚   └── CreditCardRegistryTest.java
β”‚       └── System/
β”‚           └── OrderSystemImplTest.java
β”œβ”€β”€ .gitignore
β”œβ”€β”€ PcRetailor.iml
β”œβ”€β”€ Advance Programming in Java.pdf (Technical Report)
└── README.md

πŸ’‘ Design Decisions & Rationale

Why Immutability?

  • Thread Safety: Immutable objects are inherently thread-safe
  • Reliability: Cannot be modified after creation (defensive programming)
  • Hash Integrity: Safe to use as HashMap keys

Why Factory Methods?

  • Readability: PresetModel.valueOf() is more descriptive than new PresetModel()
  • Flexibility: Can add caching or object pooling later
  • Validation: Centralized object creation with validation

Why Defensive Copying?

  • Data Integrity: Prevents external modification of internal state
  • Security: Protects sensitive data (credit card info, order details)
  • Compliance: Follows Java best practices (Effective Java, Item 50)

Why State-Based Validation?

  • Business Rules: Cannot cancel fulfilled orders (real-world constraint)
  • Data Consistency: Prevents invalid state transitions
  • Error Prevention: Fail-fast approach with clear exceptions

πŸ” Business Analytics Features

The system provides three key analytics methods:

1. Largest Customer

Map.Entry<Customer, Long> getLargestCustomer()

Returns the customer who has placed the most orders in the system.

2. Most Ordered Model

Map.Entry<String, Long> getMostOrderedModel()

Identifies the PC model with the highest order frequency.

3. Most Ordered Part

Map.Entry<String, Long> getMostOrderedPart()

Finds the most popular component across all PC configurations.

πŸ“š Documentation

Technical Report

The comprehensive technical report [Technical_Report_CSC8404.pdf] (https://drive.google.com/file/d/1ov_iNbXSqv6NhzaXlQvVMuVB_uk9DNgW/view?usp=drive_link)

  • UML class diagrams
  • Detailed class descriptions
  • Design pattern justifications
  • Implementation decisions
  • Testing strategy
  • Code quality analysis

JavaDoc Documentation

All classes include comprehensive JavaDoc comments covering:

  • Class purpose and responsibilities
  • Method descriptions with parameters
  • Return value explanations
  • Exception documentation
  • Usage examples

πŸ”— Skills Demonstrated

βœ… Object-Oriented Programming: Inheritance, polymorphism, encapsulation, abstraction
βœ… Design Patterns: Factory, Singleton, Strategy
βœ… SOLID Principles: All five principles applied
βœ… Immutability: Thread-safe immutable classes
βœ… Defensive Programming: Input validation, defensive copying
βœ… Exception Handling: Proper use of checked and unchecked exceptions
βœ… Unit Testing: Comprehensive JUnit 5 test suite
βœ… Code Documentation: JavaDoc and inline comments
βœ… Clean Code: Meaningful names, single responsibility, DRY principle
βœ… Java Best Practices: Following Effective Java guidelines

🚧 Future Enhancements

Potential improvements for production use:

  • Persistence Layer: Database integration (JPA/Hibernate)
  • REST API: Spring Boot REST endpoints
  • UI Layer: JavaFX or web-based interface
  • Authentication: User login and role-based access
  • Inventory Management: Stock tracking for parts
  • Payment Gateway: Integration with real payment processors
  • Order History: Complete audit trail of order modifications
  • Reporting: Advanced analytics and business intelligence

πŸ“ž Contact & Feedback

Student: Aniket Nalawade
Student ID: 250535354
Email: aniketnalawade277@gmail.com
GitHub: https://github.com/Aniket3434


University: Newcastle University
Program: MSc Advanced Computer Science
Module: CSC8404 - Advanced Programming in Java
Academic Year: 2025/2026


πŸ“Š Repository Stats

Java Lines of Code Test Coverage Status


Built with β˜• and dedication at Newcastle University

About

PC Order Management System - Advanced Java Programming (CSC8404) | Newcastle University MSc

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages