Question

JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

JAVA

Problem:  Coffee   

Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method:

public interface HowToMakeDrink {

public void prepare ();

}

The prepare method will simply print out the type of drink (CoffeeMocha) and all ingredients of the drink to the screen. Implement four derived classes named WhititeChocolateMocha, DarkChocolateMocha, CoffeeMocha, and PeppermintMocha.

Assign the appropriate value for chocolate Type for the first two classes. Add a peppermintSyrubAmount member variable to the PeppermintMocha class including a getter and setter function. Add a constructor to each class that sets the values of all properties. Override the prepare () method in each subclass by printing the coffee/class type and ingredients using the defined properties in that class.

Write a program that repeatedly shows the user a menu to create one of the three mocha drinks or to print all the drinks created so far. If the user selects to create a new mocha drink, the program prompts the user to enter the ingredients of the selected drink. If the user selects to print the current coffees, print the drink type and ingredients of each drink to the console. Creating objects for testing all classes and all methods in the main method

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// HowToMakeDrink.java

public interface HowToMakeDrink {

   public void prepare();

}

================================

// Coffee.java

public abstract class Coffee implements HowToMakeDrink {
private String coffeetype;
private double price;
private String storename;
  
  
   /**
   * @param coffeetype
   * @param price
   * @param storename
   */
   public Coffee(String coffeetype, double price, String storename) {
       this.coffeetype = coffeetype;
       this.price = price;
       this.storename = storename;
   }

  

   /**
   * @return the coffeetype
   */
   public String getCoffeetype() {
       return coffeetype;
   }

   /**
   * @param coffeetype the coffeetype to set
   */
   public void setCoffeetype(String coffeetype) {
       this.coffeetype = coffeetype;
   }

   /**
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * @param price the price to set
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /**
   * @return the storename
   */
   public String getStorename() {
       return storename;
   }

   /**
   * @param storename the storename to set
   */
   public void setStorename(String storename) {
       this.storename = storename;
   }

   @Override
   public void prepare() {
       System.out.println("Coffee Type :"+coffeetype);

   }
  
   public abstract void ingredient();

}

=======================================

// CoffeeMocha.java

public class CoffeeMocha extends Coffee {

   public CoffeeMocha(String coffeetype, double price, String storename) {
       super(coffeetype, price, storename);
   }

   @Override
   public void prepare() {
       System.out.println("Coffee Type :"+super.getCoffeetype());
   }

   @Override
   public void ingredient() {
       System.out.println("Ingredients :Hot milk,chocolate syrup,cocoa powder,sugar");
      
   }
}


=======================================

// DarkChocolateMocha.java

public class DarkChocolateMocha extends Coffee {

   public DarkChocolateMocha(String coffeetype, double price, String storename) {
       super(coffeetype, price, storename);
   }
  
   @Override
   public void prepare() {
       System.out.println("Coffee Type :"+super.getCoffeetype());
   }

   @Override
   public void ingredient() {
       System.out.println("Ingredients :Hot milk,ground coffee,cocoa powder,sugar,vanilla extract,whipped cream");
      
   }

}

======================================

// PeppermintMocha.java

public class PeppermintMocha extends Coffee {
   private double peppermintSyrubAmount;

   /**
   * @param coffeetype
   * @param price
   * @param storename
   * @param peppermintSyrubAmount
   */
   public PeppermintMocha(String coffeetype, double price, String storename,
           double peppermintSyrubAmount) {
       super(coffeetype, price, storename);
       this.peppermintSyrubAmount = peppermintSyrubAmount;
   }

   /**
   * @return the peppermintSyrubAmount
   */
   public double getPeppermintSyrubAmount() {
       return peppermintSyrubAmount;
   }

   /**
   * @param peppermintSyrubAmount
   * the peppermintSyrubAmount to set
   */
   public void setPeppermintSyrubAmount(double peppermintSyrubAmount) {
       this.peppermintSyrubAmount = peppermintSyrubAmount;
   }

   @Override
   public void prepare() {
       System.out.println("Coffee Type :" + super.getCoffeetype());
  
   }

   @Override
   public void ingredient() {
       System.out.println("Ingredients :Hot milk,Mocha Sauce,Brewed Espresso, Peppermint Syrup ,whipped cream");

   }

}

======================================

// WhiteChocolateMocha.java

public class WhiteChocolateMocha extends Coffee {

   public WhiteChocolateMocha(String coffeetype, double price, String storename) {
       super(coffeetype, price, storename);
   }
  
   @Override
   public void prepare() {
       System.out.println("Coffee Type :"+super.getCoffeetype());

   }

   @Override
   public void ingredient() {
       System.out.println("Ingredients :Hot milk,white chocolate sauce, espresso ,whipped cream,chocolate chips");

   }
}

=======================================

// Test.java

import java.util.ArrayList;
import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
       int choice;

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       ArrayList<Coffee> arl = new ArrayList<Coffee>();

       while (true) {
           // Getting the input entered by the user
           System.out.println("\n1.CoffeeMocha");
           System.out.println("2.DarkChocolateMocha");
           System.out.println("3.PeppermintMocha");
           System.out.println("4.WhiteChocolateMocha");
           System.out.println("5.Display All");
           System.out.println("6.Exit");
           System.out.print("Enter Choice :");
           choice = sc.nextInt();
           switch (choice) {
           case 1: {
               System.out.print("Enter Price :$");
               double price = sc.nextDouble();
               sc.nextLine();
               System.out.print("Enter Store Name :");
               String name = sc.nextLine();
               CoffeeMocha cm = new CoffeeMocha("CoffeeMocha", price, name);
               arl.add(cm);
               continue;
           }
           case 2: {
               System.out.print("Enter Price :$");
               double price = sc.nextDouble();
               sc.nextLine();
               System.out.print("Enter Store Name :");
               String name = sc.nextLine();
               DarkChocolateMocha dm = new DarkChocolateMocha(
                       "DrinkChocolateMocha", price, name);
               arl.add(dm);
               continue;
           }
           case 3: {
               System.out.print("Enter Price :$");
               double price = sc.nextDouble();
               sc.nextLine();
               System.out.print("Enter Store Name :");
               String name = sc.nextLine();
               System.out.print("Peppermint Syrub Amount :");
               double amt = sc.nextDouble();
               PeppermintMocha pm = new PeppermintMocha("PeppermintMocha",
                       price, name, amt);
               arl.add(pm);
               continue;
           }
           case 4: {
               System.out.print("Enter Price :$");
               double price = sc.nextDouble();
               sc.nextLine();
               System.out.print("Enter Store Name :");
               String name = sc.nextLine();
               WhiteChocolateMocha wcm = new WhiteChocolateMocha(
                       "WhiteChocolateMocha", price, name);
               arl.add(wcm);
               continue;
           }
           case 5:{
               displayAll(arl);
               continue;
           }
           case 6:{
               System.out.println("** Invalid Choice **");
           }
           }
          
       }

   }

   private static void displayAll(ArrayList<Coffee> arl) {
       for(int i=0;i<arl.size();i++)
       {
           arl.get(i).prepare();
           System.out.println("Price:$"+arl.get(i).getPrice());
           arl.get(i).ingredient();
           System.out.println("_____________________________");
          
       }
      
   }

}

=======================================

Output:


1.CoffeeMocha
2.DarkChocolateMocha
3.PeppermintMocha
4.WhiteChocolateMocha
5.Display All
6.Exit
Enter Choice :1
Enter Price :$12
Enter Store Name :CoffeeDay

1.CoffeeMocha
2.DarkChocolateMocha
3.PeppermintMocha
4.WhiteChocolateMocha
5.Display All
6.Exit
Enter Choice :2
Enter Price :$14
Enter Store Name :CafeCofeeDay

1.CoffeeMocha
2.DarkChocolateMocha
3.PeppermintMocha
4.WhiteChocolateMocha
5.Display All
6.Exit
Enter Choice :5
Coffee Type :CoffeeMocha
Price:$12.0
Ingredients :Hot milk,chocolate syrup,cocoa powder,sugar
_____________________________
Coffee Type :DrinkChocolateMocha
Price :$14.0
Ingredients :Hot milk,ground coffee,cocoa powder,sugar,vanilla extract,whipped cream
_____________________________

1.CoffeeMocha
2.DarkChocolateMocha
3.PeppermintMocha
4.WhiteChocolateMocha
5.Display All
6.Exit
Enter Choice :6

===============================Thank You

Add a comment
Know the answer?
Add Answer to:
JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....

    JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...

  • (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal a...

    (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...

  • Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design...

    Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design...

    This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design Interfaces Practice Activities Lesson objectives: Model business problems using Java classes Make classes immutable User Interfaces Vocabulary: Identify the vocabulary word for each definition below. A specialized method that creates an instance of a class. A keyword that qualifies a variable as a constant and prevents a method from being overridden in a subclass. A class that it can't be overridden by a subclass,...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Design and implement a Java data structure class named BookShelf which has an array to store...

    Design and implement a Java data structure class named BookShelf which has an array to store books and the size data member. The class should have suitable constructors, get/set methods, and the toString method, as well as methods for people to add a book, remove a book, and search for a book. Design and implement a Java class named Book with two data members: title and price. Test the two classes by creating a bookshelf object and five book objects....

  • A Java Program Purpose:         Work with Abstract classes. Purpose:         Abstract classes are import because they ensure...

    A Java Program Purpose:         Work with Abstract classes. Purpose:         Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem:        Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....

  • Hi I need help doing this problem *The program must re-prompt as long as invalid input...

    Hi I need help doing this problem *The program must re-prompt as long as invalid input is inserted Implement a program that manages shapes. Implement a class named Shape with a virtual function area()which returns the double value. Implement three derived classes named Diamond, Oval, and Pentagon. Declare necessary properties in each including getter and setter function and a constructor that sets the values of these properties. Override the area() function in each by calculating the area using the defined...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT