Question

In: Computer Science

Here is an outline for some code I need to write. This class used Intro to...

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.  

  • Create a parent (super class) for Beverages
  • Create a child (subclass) for Drinks you wish the Green Dragon to sell. (could be a bar, coffee shop, malt shop, etc.)
  • Create an ARRAY of Drinks to hold the recipes for the drinks sold..

Thanks!

Solutions

Expert Solution

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~


Related Solutions

I have a research about the "Nano-wafers", and i need to write an outline and some...
I have a research about the "Nano-wafers", and i need to write an outline and some points that i can address in my paper
I need an outline for this research essay so I can follow it to write the...
I need an outline for this research essay so I can follow it to write the complete essay. Please also provide me some sources and articles that can support my essay. ( Introduction: Hook + Thesis statement 3 Body Paragraph : Topic + Sources/Articles Conclusion: Final thought ) Thank you in advance. Here is my prompt: Prompt de·moc·ra·cy a form of government in which people choose leaders by voting a country ruled by democracy an organization or situation in which...
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent...
C++ Code (I just need the dieselLocomotive Class) Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of...
I need an outline for a paper that I will be writing, but I need this...
I need an outline for a paper that I will be writing, but I need this guidance. Topic: What is Bayesian Statistics/models, and what are applications, are there applications to finance? My paper will be 20 pages, about 15 of actual text. I asked this same question in another question that has been posted, so you can get 2 answered with one stone. I will like your answer as well. PLEASE help. Due tomorrow.
Here is my java code. It works and has the correct output, but I need to...
Here is my java code. It works and has the correct output, but I need to add a file and I am not sure how. I cannot use the FileNotFoundException. Please help! import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,0,0}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: "...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to use all methods, also switch statements. Write a Temperature class. The class will have three conversion methods: toCelsius(), toKelvin() and toFahrenheit(). These methods will return a Temperature in those three scales equal to the this temperature. Note that the value of this is not changed in these conversions. In addition to these three conversion methods the class will have methods add(Temperature), subtract(Temperature), multiply(Temperature), and...
Here is a Problem I need to solve: 5) Write a function to determine is a...
Here is a Problem I need to solve: 5) Write a function to determine is a given word is legal. A word is illegal if it contains no vowels. For this problem, the letter Y is considered to be a legal vowel. Pass in a word to this function and it will determine if the word is legal or not. You can make the following assumptions about the word you a passing to this function. 1) The string being passed...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
Python I am creating a class in python. Here is my code below: import csv import...
Python I am creating a class in python. Here is my code below: import csv import json population = list() with open('PopChange.csv', 'r') as p: reader = csv.reader(p) next(reader) for line in reader: population.append(obj.POP(line)) population.append(obj.POP(line)) class POP: """ Extract the data """ def __init__(self, line): self.data = line # get elements self.id = self.data[0].strip() self.geography = self.data[1].strip() self.targetGeoId = self.data[2].strip() self.targetGeoId2 = self.data[3].strip() self.popApr1 = self.data[4].strip() self.popJul1 = self.data[5].strip() self.changePop = self.data[6].strip() The problem is, I get an error saying:  ...
I have the following assignment for probability class: I am supposed to write a routine (code)...
I have the following assignment for probability class: I am supposed to write a routine (code) in MATLAB that does solve the following problem for me: a) Generate N=10000 samples of a Uniform random variable (X) using the rand () command. This Uniform RV should have a range of -1 to +3. b) Generate (Estimate) and plot the PDF of X from the samples. You are not allowed to use the Histogram () command, any commands from the Matlab Statistics...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT