Question
Make a subclass of Offering called Product. Make the Product constructor take a name and price. Implement the missing method. Submit just the Product class.
Make a subclass of Offering called Product. Make the Product constructor take a name and price. Implement the missing method. Submit just the Product class.
public abstract class Offering
{ private String name; public Offering(String n) { name = n; }
public abstract double getTotalCost();
public String toString()
{ return name + " costs $" + String.format("%.2f", getTotalCost()); } }
public class Demo1 { public static void main(String[] args)
{ Offering p1 = new Product("iPhone", 999);
Offering p2 = new Product("Movie ticket", 12);
Offering p3 = new Product("Backpack", 25);
Offering p4 = new Product("Toyota Corolla", 19000);
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.println(p4); } }
REQURED OUTPUT:
iPhone costs $999.00
Movie ticket costs $12.00
Backpack costs $25.00
Toyota Corolla costs $19000.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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