Case Study: Online Shopping System
Create a simplified online shopping system in Java, incorporating fundamental concepts such as classes, inheritance, and exception handling.
Requirements:
-
Create a
Product
Class:- Implement a
Product
class with attributesproductName
(String),productId
(int),price
(double), andquantityInStock
(int). - Include a method
displayDetails
to print details of the product.
- Implement a
-
Derived Classes -
Electronics
andClothing
:- Create two classes,
Electronics
andClothing
, that inherit from theProduct
class. - Add attributes specific to each type (e.g.,
brand
andwarrantyPeriod
for electronics,size
andmaterial
for clothing). - Override the
displayDetails
method in each derived class to include information about the specific attributes.
- Create two classes,
-
Shopping Cart:
- Create a
ShoppingCart
class to manage the user's shopping cart. - Include methods to add products to the cart, display the cart contents, and calculate the total price.
- Create a
-
User Input and Exception Handling:
- In the testing phase, simulate user input for adding electronics and clothing to the shopping cart.
- Implement exception handling to ensure valid inputs for product creation (e.g., non-empty product name, positive product ID).
- Throw DuplicateProductIDException when user tries to add product with similar id
- Add deleteProduct(int id) and throw an exception ProductNotFoundException if the product is not available;