In this exercise, you will implement a shopping cart program using an array. 1. Write a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
What is the difference between MouseListener and MouseAdapter? [3 marks] (b) Via suitable HTML, the compiled version of the following Java code is presented to the appletviewer application: import...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
A. Discuss the following conceptual model/framework of Orem's Self-Care Theory CONDITIONING FACTORS (12 MARKS) Orem's Self-Care Theory Conceptual Framework SELF-CARE AGENCY SELF-CARE DEFICIT NURSING...
-
Relate the process of abstraction to the way you take notes in a lecture. Why do you not try to transcribe every word uttered by the lecturer? Why don't you write down just the title of the lecture...
-
A call center has four categories of employees, each paid a particular wage. Managers are paid $25 an hour, clerks are paid $15 an hour, technicians are paid $20 an hour, and administrative...
-
Match each five number summary with one of the histograms in Figure 2.23. The scale is the same on all four histograms. (a) $(1,3,5,7,9)$ (b) $(1,4,5,6,9)$ (c) $(1,5,7,8,9)$ (d) $(1,1,2,4,9)$ Figure...
-
Budget Tax Service, Inc prepares tax returns for small businesses. The cost of preparing 800 tax returns in the prior year was: Direct labor ............ $320,000 Variable overhead ..............
-
A 50-ft diameter anaerobic digester with 10-ft side-wall depth treats 30,000 gpd of mixed primary and secondary sludge. The mixed sludge has a 4% total solids concentration and is 75% volatile...
-
A state machine consists of a finite number of states and is therefore also called finite-state machine (FSM). Based on the current state and a given input or conditions the machine performs state...
-
Required: a. Prepare a variance analysis for direct materials and direct labor. b. Assume that all production overhead is fixed and that the $26,900 overapplied is the only overhead variance that can...
-
Assets January 31, 2024 Liabilities Current Assets: Current Liabilities: Cash $ 84,400 Accounts Payable Accounts Receivable 47,100 Utilities Payable Supplies 7 12,600 Dividends Payable + Income Tax...
-
Tell us about a moment when you assisted your team in a key conflict concession or resolution, and how you got those individuals to agree or resolve?
-
What is a period cost for a company that manufactures baby car seats?
-
So then given that this is a credit balance on Accounts Receivable this was already considered as your liability to the customer but why was it added back on the Trade receivables when it was the...
-
What are the implications for cost accounting of lean production?
-
In Exercises 15 through 30, find the derivative dy/dx. In some of these problems, you may need to use implicit differentiation or logarithmic differentiation. y ex + et -2x 1 + e
-
We had mentioned that from the partition function \(Z\), all possible thermodynamical quantities can be determined. In this problem, we will use the harmonic oscillator's partition function of Eq....
-
Let's consider the harmonic oscillator immersed in a heat bath of temperature \(T\). For any Hermitian operator \(\hat{A}\), we can define its thermal average denoted as...
-
We had established an intriguing relationship between the path integral of the previous chapter and the partition function here through "complexification" of the time coordinate. In this problem, we...
Study smarter with the SolutionInn App