Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript Shopping Cart In this exercise, you will implement a shopping card program using an array. 1. Write a class named Item as follows. a.

JavaScript Shopping Cart

In this exercise, you will implement a shopping card program using an array.

1. Write a class named 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 printing an item as a string of price, quantity, and sub-total price (price*quantity) and getters for name, price, and quanitity.

2. Write a class named 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 to be an array holding the capacity number of items. c. The class has a method named increaseSize increasing the size of the array by 3 elements. Hint: The code is similar to that in Listing 8.7 in the text. d. The class has a method named addToCart adding the item to the cart and updating the totalPrice (note this takes into account the quantity). e. The class has toString 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. Each time through the loop read in the name, price, and quantity of the item the user wants to add 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

LO1 Summarize the organizations strategic planning process.

Answered: 1 week ago