Directions 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. For this practice problem you will need to download Shopping Trip Starting Code.zip 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 change at all to Product.java, and you should only add to ShoppingTripStartingCode.java. Do not change any code that is already present. Make sure that it is for anygiven input and not just from the example provided!!! 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 to receive credit your code needs to work for all valid inputs, not just for the particular example shown above. make sure it is for anygiven input and not just the given example!!!!!!! given code: 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(); } public class ShoppingTripStartingCode { public static void main(String[] args) { Product[] products = new Product[4]; // TODO create two necessary and two luxury products and add them to // the products array double total = 0; for (Product p : products) { // TODO print out each product total += p.getTotalPrice(); } // TODO display the total cost, rounded to the nearest cent } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Directions
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.    
For this practice problem you will need to download Shopping Trip Starting Code.zip  
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 change at all to Product.java, and you should only add to ShoppingTripStartingCode.java.  Do not change any code that is already present.

Make sure that it is for anygiven input and not just from the example provided!!! 
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 to receive credit your code needs to work for all valid inputs, not just  for the particular example shown above.

make sure it is for anygiven input and not just the given example!!!!!!!

given code:

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();
}
 
public class ShoppingTripStartingCode {

    public static void main(String[] args) {

        Product[] products = new Product[4];

        // TODO create two necessary and two luxury products and add them to
        // the products array
        double total = 0;
        for (Product p : products) {
            // TODO print out each product
            total += p.getTotalPrice();
        }

        // TODO display the total cost, rounded to the nearest cent
    }

}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY