Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this Java programming assignment: Create a shopping cart application with three classes as follows: class CartItem defines these private data members:

I need help with this Java programming assignment:

Create a shopping cart application with three classes as follows:

class CartItem

defines these private data members:

String item, double price, int quantity

defines a constructor that sets all data members when a CartItem is instantiated.

defines setters for all data members.

defines a subtotal method that returns the item price * quantity.

defines a toString method that summarizes the data for an item.

class Cart

defines these data members:

a private ArrayList of CartItem objects .

a public static double to hold the total for the cart, initial value zero.

defines a constructor that instantiates the ArrayList of cart items.

codes the method with the signature below to add a cart item and update the total:

public void add(String item, double price, int quantity)

codes a showCart method to print and number the arraylist cart items. This method also prints the cart total.

codes the following method to remove an item based on its number in the cart.

public void removeItem(int number)

class CartTest

creates a new empty Cart and then adds five or six items to it.

displays the cart.

runs a loop at least once to ask if an item should be deleted, and if so, prompts for the item number, deletes that item, and redisplays the cart.

Sample Output

1 Cart item: Echo Dot, price=29.99, quantity=3

2 Cart item: Wemo plug, price=39.99, quantity=2

3 Cart item: Ear buds, price=49.99, quantity=2

4 Cart item: Google Home, price=79.0, quantity=1

Cart total $348.93

Do you wish to remove an item before checkout (y/n)?

y

Enter item # to delete

3

1 Cart item: Echo Dot, price=29.99, quantity=3

2 Cart item: Wemo plug, price=39.99, quantity=2

3 Cart item: Google Home, price=79.0, quantity=1

Cart total $248.95

Do you wish to remove an item before checkout (y/n)?

n

1 Cart item: Echo Dot, price=29.99, quantity=3

2 Cart item: Wemo plug, price=39.99, quantity=2

3 Cart item: Google Home, price=79.0, quantity=1

Cart total $248.95

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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions