Question: Hey, I need to be done with this java assignment by tonight and I don't have enough time. 12. You will create a class that

Hey, I need to be done with this java assignment by tonight and I don't have enough time.Hey, I need to be done with this java assignment by tonight

12. You will create a class that keeps track of the total cost, average cost, and number of items in a shopping bag. Create a class called Shopping Bag. Objects of this class represent a single shopping bag. Attributes of such an object include the number of items in the bag and the total retail cost of those items. Provide a constructor that accepts a tax rate as a double argument. Provide a transformer method called place that models placing a number of identically priced items into the bag- it accepts an int argument indicating the number of items and a double argument that indicates the cost of each of the items. For example, myBag. place(5, 10.5) represents placing five items that cost $10.50 each into myBag. Provide getter methods for both the number of items in the bag and their total retail cost. Provide a total cost method that returns the total cost with tax included. Provide a toString method that returns a nicely formatted string that summarizes the current status of the shopping bag. Finally, provide a program, a "test driver," that demonstrates that your Shopping Bag class performs correctly. Create an application that repeatedly prompts the user for a number of items to put in the bag, followed by a prompt for the cost of those items. Use a 0 for the number of items to indicate that there are no more items. The program then displays a summary of the status of the shopping bag. Assume the tax rate is 6%. A short sample run might look something like this: Enter count (use 0 to stop): 5 Enter cost: 10.50 Enter count (use 0 to stop): 2 Enter cost: 2.07 Enter count (use 0 to stop): 0 The bag contains seven items. The retail cost of the items is $56.64. The total cost of the items, including tax, is $60.04

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!