Question
The total cost of a group of items at a grocery store is based on the sum of the individual product prices and the tax
The total cost of a group of items at a grocery store is based on the sum of the individual product prices and the tax (which is 5.75%). Products that are considered "necessities" are not taxed, whereas products that are considered "luxuries" are.
You will need to use the Shopping Trip Starting Code and product code I attached photos of below.
The Product class is abstract, and it has a method called getTotalPrice. Your task is to create two subclasses of Product: NecessaryProduct and LuxuryProduct and implement the getTotalPrice method in each of these classes appropriately. Then modify the driver program to instantiate four products (two necessary and two luxury) and store them in the product array, print out each item in the array, and display the total cost of the items.
You should not make any changes at all to Product.java, and you should only add to ShoppingTripStartingCode.java. Do not change any code that is already present.
Example
(Cheese and bread are necessities and soda and candy are luxuries) Cheese $1.50 Soda $3.50 Bread $2.25 Candy $2.00 The total cost is $9.57 The computation is 1.50 + (3.50 * 1.0575) + 2.25 + (2.00 * 1.0575) = 9.57. Note that the price displayed next to each product is the price without tax. Keep in mind that the code needs to work for all valid inputs, not just for the particular example shown above.
CoursHeroTranscribedText*Product - Notepad File Edit Format View Help public abstract class Product { } private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } @Override public String toString() { return String.format("%s $%.2f", name, price); } public double getPrice() { return price; } public abstract double getTotalPrice();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a solution to implement the necessary subclasses of Product NecessaryProduct and LuxuryProduct ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started