Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedundef

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;

}

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago