Question: You will create a class that keeps track of the total cost, average cost, and number of items in a shopping bag. a.You will create
You will create a class that keeps track of the total cost, average cost, and number of items in a shopping bag.
a.You will create a class that keeps track of the total cost, average cost, and number of items in a 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 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 ive 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.
(1) Your UML class diagram and code are consistent
(2) Your program is working properly even if different parameters are given
(3) Your program follows an object-oriented approach
You need to create and use an object of your ShoppingBag class in the main() method.
If your test driver does not have something like ShoppingBag myBag = new ShoppingBag(8.0), myBag.place(3, 10.00);, and myBag.toString();, it is not object-oriented design.
For user input (tax rate, number of items, unit price), you may use Scanner class to read in or hardcode it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
