Question

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 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
Answer #1

Save all these files in the same folder

1 // Save this as HowToMakeDrink.java 2 3 4 5 public interface HowToMakeDrink { public void prepare(); }

// Save this as "HowToMakeDrink.java"

public interface HowToMakeDrink {

    public void prepare();

}

1 2 3 // Save this as Coffee.java poblic abstract class Coffee implements HowToMakeDrink { private String coffeetype; priva

// Save this as "Coffee.java"

public abstract class Coffee implements HowToMakeDrink {

    private String coffeetype;

    private double price;

    private String storename;

    public Coffee(String coffeetype, double price, String storename) {

        this.coffeetype = coffeetype;

        this.price = price;

        this.storename = storename;

    }

    public String getCoffeetype() {

        return coffeetype;

    }

    public void setCoffeetype(String coffeetype) {

        this.coffeetype = coffeetype;

    }

    public double getPrice() {

        return price;

    }

    public void setPrice(double price) {

        this.price = price;

    }

    public String getStorename() {

        return storename;

    }

    public void setStorename(String storename) {

        this.storename = storename;

    }

    public void prepare() {

        System.out.println("Coffee Type :" + coffeetype);

    }

    public abstract void ingredient();

}

// CoffeeMocha.java public class coffeeMocha extends Coffee { 2 3 4 public CoffeeMocha(String coffeetype, double price, strin

// CoffeeMocha.java

public class CoffeeMocha extends Coffee {

    public CoffeeMocha(String coffeetype, double price, String storename) {

        super(coffeetype, price, storename);

    }

    public void prepare() {

        System.out.println("Coffee Type :" + super.getCoffeetype());

    }

    public void ingredient() {

        System.out.println("Ingredients :Hot milk,chocolate syrup,cocoa powder,sugar");

    }

}

1 // Save this as DarkchocolateMocha.java peblic class DarkchocolateMocha extends Coffee { 2 3 4 5 public DarkChocolateMoch

// Save this as "DarkChocolateMocha.java"

public class DarkChocolateMocha extends Coffee {

    public DarkChocolateMocha(String coffeetype, double price, String storename) {

        super(coffeetype, price, storename);

    }

    public void prepare() {

        System.out.println("Coffee Type :" + super.getCoffeetype());

    }

    public void ingredient() {

        System.out.println("Ingredients :Hot milk,ground coffee,cocoa powder,sugar,vanilla extract,whipped cream");

    }

}

1 2 !! PeppermintMocha.java public class PeppermintMocha extends Coffee { private double peppermintsyrubAmount; 3 4 5 6 7 pub

// PeppermintMocha.java

public class PeppermintMocha extends Coffee {

    private double peppermintSyrubAmount;

    public PeppermintMocha(String coffeetype, double price, String storename, double peppermintSyrubAmount) {

        super(coffeetype, price, storename);

        this.peppermintSyrubAmount = peppermintSyrubAmount;

    }

    public double getPeppermintSyrubAmount() {

        return peppermintSyrubAmount;

    }

    public void setPeppermintSyrubAmount(double peppermintSyrubAmount) {

        this.peppermintSyrubAmount = peppermintSyrubAmount;

    }

    public void prepare() {

        System.out.println("Coffee Type :" + super.getCoffeetype());

    }

    public void ingredient() {

        System.out.println("Ingredients :Hot milk,Mocha Sauce,Brewed Espresso, Peppermint Syrup ,whipped cream");

    }

}


1 2 3 Save this as WhiteChocolate Mocha.java public class White ChocolateMocha extends coffee { 4 public WhiteChocolate Moc

// Save this as "WhiteChocolateMocha.java"

public class WhiteChocolateMocha extends Coffee {

    public WhiteChocolateMocha(String coffeetype, double price, String storename) {

        super(coffeetype, price, storename);

    }

    public void prepare() {

        System.out.println("Coffee Type :" + super.getCoffeetype());

    }

    public void ingredient() {

        System.out.println("Ingredients :Hot milk,white chocolate sauce, espresso ,whipped cream,chocolate chips");

    }

}

1 2 3 [Test.java import java.util.ArrayList; import java.util.Scanner; 4 5 6 public class Test { Run | Debug public static vo

38 39 DarkchocolateMocha dm = new DarkchocolateMocha(Drinkchocolate Mocha, price, name); arl.add(dm); continue; 40 41 } 42

54 55 56 57 58 59 60 61 case 4: { System.out.print(Enter Price :$); double price = sc.nextDouble(); sc.nextLine(); System.o

// Test.java

import java.util.ArrayList;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {

        int choice;

        Scanner sc = new Scanner(System.in);

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

        while (true) {

            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("_____________________________");

        }

    }

}

//PLEASE LIKE IT RAISE YOUR THUMBS UP
//IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION

Add a comment
Know the answer?
Add Answer to:
JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

  • 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...

  • 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,...

  • 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,...

  • (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...

  • 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...

  • 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...

  • Use stacks to implement a program in JAVA that will prompt the use to type a...

    Use stacks to implement a program in JAVA that will prompt the use to type a word, then print that word in reverse order of letters, then ask the user for another word, and so on. The program should terminate when the user enters "STOP" in upper case. Your deliverables shall include: class and method specifications; class and method definitions; at test class with at least two @test methods.

  • 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....

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