Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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;
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;
}
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 SodaStep 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