Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following task in this Assignment 1. Provide a method getSubTotal() in the line Item class. This method will return the subtotal of this

Complete the following task in this Assignment

1. Provide a method getSubTotal() in the line Item class. This method will return the subtotal of

this item. For example if you bought a Product whose unit price was Rs. 10 and the quantity you

bought is 4 then the subtotal of this line item will be Rs. 40. You already have all the necessary

information available in the lineitem class.

2. You would have created an arraylist instance in main to hold the line items included in a sale.

Now you are required to take all of this code into a class ShoppingBag. This class represents the

actual Sale that has occurred. In order to do this you will have to create an ArrayList within this

class which will hold lineitem instances. Provide the following in your ShoppingBag class

a. An arraylist to hold lineitems

b. A reference to a Catalog Instance (This is aggregation of catalog)

c. A constructor with one argument for the Caltalog reference

i. Initialize the reference with the passed value

d. Provide a method addItem(int code, int quantity)

i. Use the catalog reference to get the Product with the code and then create a

lineitem instance set with this product and quantity. Add this lineitem to the

arraylist in ShoppingBag Class

e. Provide a method removeItem(int c)

i. This method finds a lineitem which represents the sale of a product with the

code c from the arraylist and then removes it

f. Provide a method getTotalCost(). This method computes the total cost of the shopping

bag.i.e. the total price of all items purchased according to their quantity. For this you

can use the getSubTotal method of the lineitem class for each lineitem instance.

3. Incorporate the new elements in your main and call different methods to test your

implementation

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

Students also viewed these Programming questions