Question: undef public class Drink { final private String name; protected double price; public Drink(String name, double price) { this.name = name; setPrice(price); } public String

undef public class Drink { final private String name; protected double price;undef

public class Drink {

final private String name;

protected double price;

public Drink(String name, double price)

{

this.name = name;

setPrice(price);

}

public String getName() {

return name;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public Drink(String name, double price) { this.name = name; setPrice(price); } public

Soda 1. Write a java class Soda that extends the Drink class below. Class Soda has one instance variable calories (int). (1%) Create a constructor in Soda using inheritance approach. (1.5%) Create setters and getters for the instance variable. Calories should not be less than zero. The program will exit if not. (1.5%) Write a toString method to correctly call protected and private members in Drink and to print the output as follows: (1%) Drink Name: Pepsi Price: 0.75 Calories: 150 Drink Name: Diet Pepsi Price: 0.75 Calories: 10 public class Drink { final private String name; protected double price; You have an inheritance relation (is-a) as shown below: Drink Soda

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!