Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class that keeps track of the total cost, average cost, and number of items in your shopping bag. a. Create a class called

Create a class that keeps track of the total cost, average cost, and number of items in your shopping bag.

a. Create a class called ShoppingBag. Objects of this class represent a single shopping bag. Attributes of such an object include the number of items in a 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 totalCost 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 ShoppingBag class performs correctly.

b. 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

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_2

Step: 3

blur-text-image_3

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions