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: g

Sagot :

Answer:

interface HowToMakeDrink{

   public void ingredient();

   public void makeDrink();

}

class Coffee implements HowToMakeDrink{

   String type;

   double price;

   String name;

   public void ingredient(String ...items){

       for (String i : items){

           System.out.println('%s\n', i);

       }

   }

   public makeDrink(){

       System.out.println('Your '+ %s +' is ready', this.name);

   }

   public getType(){

       return this.type;

   }

   public getPrice(){

       return this.price;

   }

   public getName(){

       return this.name;

   }

   public setType(String type){

       this.type = type;

   }

   public setPrice(double price){

       this.price = price;

   }

   public setName(String name-){

       this.name = name;

   }

}

Explanation:

The Coffee class is used to implement the HowToMakeDrink interface. The class uses the set and get methods to assign and retrieve the values of the class variables. It so implements the ingredient and makeDrink methods of the required interface.