Objective: Class composition In an online shopping web application, the user views several items to buy. Each item can be added to the shopping cart. When the user check-out, all the items in the shopping cart are listed and the total price is computed. A.
Design and Implement aclass which can hold up to 20 Items. Use a normal array as a container for the items. The ShoppingCart class must have the following attributes and methods: Class attributes: All items must be declared private a. itemList defined as 1 dimensional array composed of the previously user defined Item data type (class) and holds a maximum size of 20 items.(refer to lab 4) numltems an integer represents the total number of items currently in the shopping cart defaulted to zero. b. Class constructors Only a default constructor should be defined to create an empty shopping cart. When this constructor is called, it should initialize the array itemList and set the numltems to zero ShoppingCart Class methods: a. Class Methods a. addltem(ltem anltem): this method take anlTem as input and add it to the itemList array. Each time an item is added, the numitem must be incremented. This methods returns nothing (void). removeltem(String itemname): this method takes an item name and remove it from the shopping cart itemList. If the item was removed correctly, this methods return true Boolean value. If the item is not in the itemList, it should return false Boolean value. b. c. checkout0: this method will print out a list of all items in the shopping cart and count and print the total items price. Note: you have to apply good programming style and documentation in developing and maintaining your codes. B. Use the previously implemented Class to test by doing the following 1. 2. 3. 4. Define a ShoppingCart Add the items to the shopping cart Remove one item from the shopping cart Checkout and display the total of the items in the cart. Note: you have to apply good programming style and documentation in developing and maintaining your codes public class Item ( private String code private String name private double price; public ItemO ( code name price 0.0; public Item(String code, String name, double price) ( this.code code; this.name name; this.price price; public void setCode(String code)( this.code code; public void setName(String name) ( this.name name public void setPrice(double price) this.price price public String getCode0 return code public String getNamel ( public String getName0 ( return name public double getPrice)( return price; public String toString0 return "Item code:" +code+"name: name+"price:"+ price class OnlineShopping ( public static void main(String] args) ( Item i- new Item("001", "lphone, 3000.00); System.out.println(); i.setName lphoneX) System.out.println(i.getCode0): System.out.println() Item j new Item0 j.setCodef"O02") j.setName("Nexus); j.setPrice(2000.00); System.out.println(j.getCode0) System.out.println(j.getName0) System.out.printlnG. System.out.println): getPrice0