Question: In this exercise, you will implement a shopping cart program using an array. 1. Write a class Item as follows. a. The class has


In this exercise, you will implement a shopping cart program using an array. 1. Write a class Item as follows. a. The class has attributes of a name, price, and quantity (the quantity purchased) which are initialized in the constructor by the corresponding parameters of the constructor. b. The class has toString for printing an item as a string of price, quantity, and sub-total price (price*quantity) and getters for name, price, and quantity. 2. Write a class ShoppingCart as follows. a. The class has attributes of itemCount, totalPrice, and capacity which are initialized to 0, 0, and 5 respectively in the constructor. b. The class has a cart implemented as an array of items. cart is instantiated in the constructor with the capacity number of items. c. The class has the increaseSize method to increase the size of the array by 3 elements. (Hints: It is similar to the increaseSize() method in Listing 8.8 in the text) d. The class has the addToCart method for adding an item to the cart and updating totalPrice (Note: This should consider the quantity). e. The class has the toString method for printing a cart as a string of all the items in the cart with the grand total price. 3. Write the driver class Shopping that simulates shopping. The class should have a loop that continues as long as the user wants to shop up to two times of size increase of capacity (e.g., if capacity is 5, it can be increased up to 11 each time increased by 3). In the loop, the user provides the name, price, and quantity of the item being added to the cart. After adding an item to the cart, the cart contents should be printed. After the loop print a "Please pay ..." message with the total price of the items in the cart. Deliverables The program and the final execution. UML class diagram. Example Output Welcome to the Shopping Buddy Pro! Enter in the name of the item: Markers Enter in the item price: 4 Enter in the item quantity 1 Shopping Cart Item Markers Unit Price Quantity $4.00 1 Total $4.00 Total Price: $4.00 Enter Y if you would like to keep shopping or Enter N to quit Y Enter in the name of the item: CellPhone Enter in the item price: 6 Enter in the item quantity 3 Shopping Cart Item Unit Price Quantity Total Markers $4.00 1 $4.00 CellPhone $6.00 3 $18.00 Total Price: $22.00 Enter Y if you would like to keep shopping or Enter N to quit n Thanks for Shopping with Shopping Buddy Pro! Please pay 22.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
