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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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 (which is 5.75%).  Products that are considered  “necessities”    are not taxed, whereas products that  are  considered  “luxuries” are.     

 

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.

J Product.java X
C: > Users >
1
2
3
4
5
6
7
8
9
SENEGAGAANN
10
11
12
13
14
15
16
17
18
19
20
> AppData > Local > Temp >
public abstract class Product {
21 }
22
private String name;
private double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
Temp2_Shopping Trip Starting Code.zip > Shopping Trip Starting Code > J Product.java
@Override
public String toString() {
return String.format("%s $ %.2f", name, price);
}
public double getPrice() {
return price;
8
public abstract double getTotalPrice ();
Transcribed Image Text:J Product.java X C: > Users > 1 2 3 4 5 6 7 8 9 SENEGAGAANN 10 11 12 13 14 15 16 17 18 19 20 > AppData > Local > Temp > public abstract class Product { 21 } 22 private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } Temp2_Shopping Trip Starting Code.zip > Shopping Trip Starting Code > J Product.java @Override public String toString() { return String.format("%s $ %.2f", name, price); } public double getPrice() { return price; 8 public abstract double getTotalPrice ();
J Product.java
J Shopping TripStartingCode.java X
> AppData > Local > Temp > Temp2_Shopping Trip Starting Code.zip > Shopping Trip Starting Code > J Shopping TripStart
public class Shopping TripStartingCode {
1
2
CEEEEEEEEE
10
11
12
13
14
15
16
19
}
Run | Debug
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
Transcribed Image Text:J Product.java J Shopping TripStartingCode.java X > AppData > Local > Temp > Temp2_Shopping Trip Starting Code.zip > Shopping Trip Starting Code > J Shopping TripStart public class Shopping TripStartingCode { 1 2 CEEEEEEEEE 10 11 12 13 14 15 16 19 } Run | Debug 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
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education