Question: Objective In the assignment, you will be practicing one of Javas collections called ArrayList which is in the util package. Click here to see the
Objective
In the assignment, you will be practicing one of Javas collections called ArrayList which is in the util package. Click here to see the ArrayList class description and its methods.
Problem
You are going to create an online shopping store allowing customers to purchase items and place them in their shopping carts. Once the customer is ready they will check out the list of the purchased items and the total money that needs to be paid including the shipping and the tax amount. What kind of items would you like to sell in your virtual store? Feel free to add attributes and functionalities(methods) to the classes if needed. This will be your store so make sure that all the functionalities are working properly.
Requirements
- you work must satisfy all the criteria listed in the rubrics
- must have all the methods
- Fell free to add more methods/functionalities
- Feel free to use your logic for implementing each method.
- The description of each method is given in the provided java shell
Method descriptions
The descriptions for the methods in the different classes are given in the provided java shell.
Required classes
- item class
- onlineItem class (an OnlineItem is an Item)
- ShoppingCart class (A ShoppingCart has OnlineItems in it)
- driver class
Item class
Create the item class based on the following UML. Compile your code as you add more methods.
| Item |
| - barCode: String -price: double //price of the item cannot be negative - name: String //name of the item -description: String // description of the item -quantity: int //quantity that can be purchased, cannot be negative |
| +Item(String barcode, double price, String name, String description, int quantity) +getPrice() : double +getQuantity() : int +getDescription(): String +getBarCode(): String +setPrice(double price): Boolean //if the price is negative returns false and the price will not be changed +setQuantity(int q) : Boolean //if the price is negative returns false and the price will not be changed +setDescription(String des):void setBarCode(String code) : void +toString() : String //returns a string representing the item including all the attributes +equals (Object o) : boolean // compares two items based on the bar code. Type cast the object o first +getTotal (): double //returns the total cost of the item based on the quantity |
OnlineItem class
This class extends the Item class since onLineItem is an Item
| OnlineItem extends Item |
|
- weight: double // this attribute is used to calculate the shipping cost
|
| +OnlineItem(String bar, String name, String description, int quantity, double price, double weight) +getWeight() : double +toString():String
|
OnlineShoppingCart
This class should have a list of the online items since a shopping cart has shopping items in it. There is a has-a relationship between this class and the onlineItem class. This class has the most work since it will be calling methods from other two classes.
| OnlineShoppingCart |
| public static final int SHIP_RATE = 3; -list : ArrayList |
| +OnlineShoppingCart() +getList(): ArrayList +remove(): Boolean +add(): void +checkout():void +changeQuantity(): Boolean +toString(): String +totalPurchaseAmount(): double +totalWeight(): double shippingCost() |
Driver class
- Once you have implemented all the classes copy and paste the following code in the main method. then run your program.
- Write your own code by creating another shopping cart and putting item in it.
| OnlineShoppingCart myCart = new OnlineShoppingCart(); OnlineItem item1 = new OnlineItem("123456", "Shirt", "red cotton", 1, 15.00, 1.3); myCart.add(item1); OnlineItem item2 = new OnlineItem("23", "Shoes", "Addidas", 1, 55, 2); myCart.add(item2); OnlineItem item3 = new OnlineItem("987", "Basketball", "Addidas", 1, 25, 3); myCart.add(item3); OnlineItem item4 = new OnlineItem("5643", "Camera", "Kodak", 1, 150, 2.3); myCart.add(item4); //reviewing the cart System.out.println(myCart); //checking out myCart.checkout() ;
|
Sample output:
Your Shopping Cart
Item: Shirt Description: red cotton Barcode: 123456 Quantity: 1 Price: 15.0 total: 15.0 ****
Item: Shoes Description: Addidas Barcode: 23 Quantity: 1 Price: 55.0 total: 55.0 ****
Item: Basketball Description: Addidas Barcode: 987 Quantity: 1 Price: 25.0 total: 25.0 ****
Item: Camera Description: Kodak Barcode: 5643 Quantity: 1 Price: 150.0 total: 150.0 ****
******************************* Checking out ******************************* Your Shopping Cart
Item: Shirt Description: red cotton Barcode: 123456 Quantity: 1 Price: 15.0 total: 15.0 ****
Item: Shoes Description: Addidas Barcode: 23 Quantity: 1 Price: 55.0 total: 55.0 ****
Item: Basketball Description: Addidas Barcode: 987 Quantity: 1 Price: 25.0 total: 25.0 ****
Item: Camera Description: Kodak Barcode: 5643 Quantity: 1 Price: 150.0 total: 150.0 ****
Subtotal: 245.0 Tax: 18.9875
Free Shipping Amount due: 263.99
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
