Question

Make a subclass of Offering called Product. Make the Product constructor take a name and price....

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\n

Movie ticket costs $12.00\n

Backpack costs $25.00\n

Toyota Corolla costs $19000.00\n

0 0
Add a comment Improve this question Transcribed image text
Answer #1

All classes code is as follows:

Product.java

*****************************************************************************************************************

public class Product extends Offering{
double cost;
Product(String name,double cost){
super(name);
this.cost = cost;
}
public double getTotalCost(){
return cost;
}
}

*****************************************************************************************************************

Offering.java

*****************************************************************************************************************

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());
  
}
  
}

*****************************************************************************************************************

Demo1.java

*****************************************************************************************************************

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); } }

*****************************************************************************************************************

Output:

Add a comment
Know the answer?
Add Answer to:
Make a subclass of Offering called Product. Make the Product constructor take a name and price....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Calculates the distance between two points of N dimensional space. If the two points are in...

    Calculates the distance between two points of N dimensional space. If the two points are in different dimensions, print the distance as -1. Use Euclid Distance and Manhattan Distance. Thanks! **Use the code below and complete the rest.** public class Distance2 { public static void main(String[] args) { Point p1 = new Point(new double[] {1.0, 2.0, 3.0}); Point p2 = new Point(new double[] {4.0, 5.0, 6.0}); System.out.println("Euclidean Distance: " + EuclidDistance.getDist(p1, p2)); System.out.println("Manhattan Distance: " + ManhattanDistance.getDist(p1, p2)); Point p3...

  • Given two polynomials equation, write a function that adds and multiply the given two polynomials. It...

    Given two polynomials equation, write a function that adds and multiply the given two polynomials. It adds and multiply  the two equations which are in standard form and return them in the sum poly which also be in standard form. Write one add method and one multiply method. public class pll { public static void main(String argc[]) { PLL ans_sum,ans_mul; PLL p1 = new PLL(4, 2); PLL p2 = new PLL(6, 5); p3 = p1.add(p2); p1 = new PLL(2, 4); p2...

  • I have this java program that I need to add an abstract method and polymorphism to...

    I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...

  • Add Encapsulation , Set and get to this program: import java.util.*; abstract class BookTheTicket {//abstract class...

    Add Encapsulation , Set and get to this program: import java.util.*; abstract class BookTheTicket {//abstract class private String movieName; private String theatreName; private int ticketCost; abstract void viewAvailablerefreshments();//abstract method void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.Men in Black ------------ $40 \n 2.Toy story---------$.50 \n 3.Harry Potter --------$60"+ "\n 4.lord of the rings ----- $.70 \n 5.the hobbit ----- $.80 "); } } import java.util.Scanner; class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.VOX...

  • Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class...

    Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class named, “Games2”. 2. Create a Player class and add this code: public class Player { private String name; private int points; public Player(String name, int points) { this.name = name; this.points = points; } public String getName() { return name; } public int getPoints() { return points; } @Override public String toString() { return "name=" + name + ", points=" + points; } }...

  • Create a class to represent a term in an algebraic expression. As defined here, a term...

    Create a class to represent a term in an algebraic expression. As defined here, a term consists of an integer coefficient and a nonnegative integer exponent. E.g. in the term 4x2, the coefficient is 4 and the exponent 2 in -6x8, the coefficient is -6 and the exponent 8 Your class will have a constructor that creates a Term object with a coefficient and exponent passed as parameters, and accessor methods that return the coefficient and the exponent. Your class...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

  • HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

    HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT