Sprint Challenge: Advanced Java Concepts
Challenge Overview
This Sprint Challenge allows you to demonstrate your understanding of encapsulation, polymorphism, interfaces, generics, and primitive wrapper classes. You'll apply these concepts by creating a virtual E-Commerce Platform with multiple product types, shopping carts, and order processing.
Challenge Objectives
In this Sprint Challenge, you will:
- Implement encapsulation to protect your system's internal data
- Use polymorphism to handle different product types with common behaviors
- Create and use interfaces for e-commerce operations
- Apply generics for type-safe collections of products
- Work with primitive wrapper classes for data conversion
Project Description: E-Commerce Platform
Your task is to implement a virtual e-commerce platform with several key components:
1. Products System
- Create a
Product
interface with common behaviors - Implement different product types (Electronics, Books, Clothing)
- Apply encapsulation principles to protect product data
2. Shopping Cart
- Design a generic
ShoppingCart
class - Implement methods to add, remove, and calculate totals
- Use proper data hiding and validation
3. Order Processing
- Create an order processing system with different payment methods
- Apply polymorphism for different payment methods
- Use primitive wrapper classes for currency handling
Requirements
Product Interface and Implementations
Define a Product
interface with the following methods:
public interface Product {
String getId();
String getName();
double getPrice();
int getInventoryCount();
void decreaseInventory(int amount);
}
Implement at least three different product types:
Electronics
with warranty period and manufacturerBook
with author and ISBNClothing
with size and color
Generic Shopping Cart
Create a generic ShoppingCart
class:
public class ShoppingCart<T extends Product> {
// Add your implementation
// Should include methods to add products, remove products, calculate total
// Calculate total price with tax
// Should have method to checkout (creates an order)
}
Payment Processing
Create a payment system with interfaces:
public interface PaymentProcessor {
boolean processPayment(Double amount);
String getPaymentMethod();
}
// Implement at least two payment methods (CreditCard, PayPal, etc.)
Order System
Create an Order
class that encapsulates:
- Order ID and customer information
- List of products purchased
- Order date and status
- Payment method used
Testing Your Implementation
Create a Main
class with a demonstration of your e-commerce platform:
public class Main {
public static void main(String[] args) {
// Create some products
Product laptop = new Electronics("E001", "Laptop", 999.99, 10, "TechCorp", 12);
Product book = new Book("B001", "Java Programming", 49.99, 50, "Jane Smith", "123-456-789");
Product shirt = new Clothing("C001", "T-Shirt", 19.99, 100, "M", "Blue");
// Create a shopping cart and add products
ShoppingCart<Product> cart = new ShoppingCart<>();
cart.addProduct(laptop);
cart.addProduct(book);
cart.addProduct(shirt);
// Display cart contents and total
System.out.println("Cart Contents:");
cart.displayCart();
System.out.println("Total: $" + cart.calculateTotal());
// Process payment and create order
PaymentProcessor creditCard = new CreditCardPayment("1234-5678-9012-3456", "12/24", "123");
Order order = cart.checkout("John Doe", "john@example.com", creditCard);
// Display order details
System.out.println("\nOrder created: " + order.getId());
System.out.println("Status: " + order.getStatus());
}
}
Additional Challenge Requirements
- Implement proper encapsulation for all classes
- Use defensive copying where appropriate
- Apply the final keyword strategically
- Implement appropriate equals() and hashCode() methods
- Include appropriate exception handling
- Add meaningful Javadoc comments
Stretch Goals:
- Implement a discount system with different discount strategies
- Add an inventory management system
- Create a customer loyalty program
Submission Requirements
To complete this Sprint Challenge, submit the following:
- Your complete Java project with all required classes and interfaces
- A README.md file explaining your implementation decisions
- Demonstration of your application running with sample output