In: Computer Science
Here is an outline for some code I need to write. This class used Intro to Java Edition 11, and we only got to Chapter 9. There is no set right way that this program has to be done. Feel free to interpret this in a way that you wish.
Mrs. Quackenbush is back! She now has bought a beverage establishment, The Green Dragon Inn, and needs to have a way to insure the consistency of the drinks her employees serve. Your company has the task of providing a user-friendly way for Mrs. Q's customers to receive the same high quality at each visit. This program is a kind of evaluation of what you have learned this semester, so you should be careful to insure user-friendliness and programmer-friendliness throughout.
Thanks!
public class Beverage {
private String name;
private double price;
// constructors
public Beverage(String name, double price) {
this.name = name;
this.price = price;
}
public Beverage(String name) {
this.name = name;
this.price = 0;
}
// getters and setters
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(double price) {
this.price = price;
}
// toString - for display
public String toString() {
return "Beverage (name: " + name +
", price: $" + price + ")";
}
}
_________________________________
public class Coffee extends Beverage {
private String flavour;
// constructors
public Coffee(String name, double price, String
flavour) {
super(name, price);
// Beverage
this.flavour = flavour;
}
public Coffee(String name, String flavour) {
super(name);
//
Beverage
this.flavour = flavour;
}
// getter and setter
public String getFlavour() {
return flavour;
}
public void setType(String flavour) {
this.flavour = flavour;
}
// toString - for display
public String toString() {
return "Coffee (Name: " + getName()
+ ", Flavour: " + flavour + ", price: $" + getPrice() + ")";
}
}
______________________________
public class Tea extends Beverage {
private String spice;
// constructors
public Tea(String name, double price) {
super(name, price);
// Beverage
this.spice = "none";
}
public Tea(String name, double price,String spice)
{
super(name, price);
// Beverage
this.spice = spice;
}
public Tea(String name) {
super(name);
//
Beverage
this.spice = "none";
}
public Tea(String name, String spice) {
super(name);
this.spice = spice;
}
// getter and setter
public String getSpice() {
return spice;
}
public void setSpice(String spice) {
this.spice = spice;
}
// toString - for display
public String toString() {
return "Tea (Name: " + getName() +
", Spice: " + spice + ", price: $" + getPrice() + ")";
}
}
______________________________
// Driver program to apply the three classes Beverage,Coffee and Tea
public class GreenDragon {
public static void main(String[] args) {
// An array drinks to hold the
recipes for the drinks sold
Beverage drinks[] = { new
Coffee("Arabica",50,"Vanilla"),
new Coffee("Robusta",45," Caramel
Macchiato"),
new Tea("Oolong",30,"Ginger")};
// display using loop
System.out.println("---------GREEN
DRAGON TODAY---------");
for(int i=0; i<drinks.length;
i++)
System.out.println(drinks[i].toString());
}
}
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~