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 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.
Hi,
Java classes below. Prices of the coffees are assumed. Please correct the values.
------------------------
/**
*
*/
package coffee;
import java.util.ArrayList;
import java.util.Scanner;
/*******************************************************
* @author
* CoffeeDriverMain.java
*******************************************************/
public class CoffeeDriverMain {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner sc = new
Scanner(System.in);
ArrayList<Coffee>
coffeeList = new ArrayList<Coffee>();
int coffeeOption;
int menuChoice;
do{
System.out.println("---------- Coffee Menu -----------");
System.out.println("1.Coffee Type.");
System.out.println("2.Print Coffee Mochas.");
System.out.println("3.Exit The Program. -->");
System.out.println("----------------------------------");
System.out.println("Please enter your menu choice:= ");
menuChoice = sc.nextInt();
switch (menuChoice){
case 1:
System.out.println("1.WhititeChocolateMocha");
System.out.println("2.DarkChocolateMocha");
System.out.println("3.CoffeeMocha");
System.out.println("4.PeppermintMocha");
System.out.println("Please enter coffee:= ");
coffeeOption = sc.nextInt();
switch (coffeeOption){
case 1:
WhititeChocolateMocha whititeChocolateMocha =
new WhititeChocolateMocha();
whititeChocolateMocha.ingredient();
coffeeList.add(whititeChocolateMocha);
break;
case 2:
DarkChocolateMocha darkChocolateMocha = new
DarkChocolateMocha();
darkChocolateMocha.ingredient();
coffeeList.add(darkChocolateMocha);
break;
case 3:
CoffeeMocha coffeeMocha = new
CoffeeMocha();
coffeeMocha.ingredient();
coffeeList.add(coffeeMocha);
break;
case 4:
PeppermintMocha peppermintMocha = new
PeppermintMocha();
peppermintMocha.ingredient();
coffeeList.add(peppermintMocha);
}
break;
case 2:
for (Coffee coffee : coffeeList) {
System.out.println("Coffee Type: " + coffee.getType());
System.out.println("Price: " + coffee.getPrice());
coffee.prepare();
}
break;
case 3:
System.out.println("Program Exit.Thanks for
visiting Coffee Bucks.");
System.out.println("Have a nice day. Good
Bye!");
break;
default:
System.out.println("Invalid Option!");
}
}while
(menuChoice!=3);
}
}
----------------------------------------------------------
/**
*
*/
package coffee;
import java.util.Scanner;
/**
* @author
*
*/
public class PeppermintMocha extends Coffee {
private double peppermintSyrubAmount;
public PeppermintMocha() {
type =
"PepperMintMocha";
price = 20.00;
}
public double getPeppermintSyrubAmount()
{
return
peppermintSyrubAmount;
}
public void setPeppermintSyrubAmount(double
peppermintSyrubAmount) {
this.peppermintSyrubAmount = peppermintSyrubAmount;
}
@Override
void ingredient() {
Scanner sc = new
Scanner(System.in);
System.out.print("Please
enter the amount of peppermint(ml):= ");
double amountPeppermint
= sc.nextDouble();
setPeppermintSyrubAmount(amountPeppermint);
}
@Override
public void prepare() {
System.out.println("Peppermint in ml:= " +
getPeppermintSyrubAmount());
}
}
--------------------------------------------------
/**
*
*/
package coffee;
import java.util.Scanner;
/**
* @author
*
*/
public class CoffeeMocha extends Coffee {
private String[] ingredients;
public CoffeeMocha() {
type =
"CoffeeMocha";
price = 15.00;
}
@Override
void ingredient() {
Scanner sc = new
Scanner(System.in);
System.out.print("Please
enter the number of ingredients:= ");
int numIngredients =
sc.nextInt();
sc.nextLine();
ingredients = new
String[numIngredients];
for(int
i=0;i<numIngredients;i++){
ingredients[i] = sc.nextLine();
}
}
@Override
public void prepare() {
System.out.println("CoffeeMocha ingredients:= ");
for(int i = 0; i<
ingredients.length; i++){
System.out.println("Ingredient " + ingredients[i]);
}
}
}
----------------------------------------
/**
*
*/
package coffee;
import java.util.Scanner;
/**
* @author
*
*/
public class DarkChocolateMocha extends Coffee {
private String[] ingredients;
public DarkChocolateMocha() {
type =
"DarkChocolateMocha";
price = 10.00;
}
@Override
void ingredient() {
Scanner sc = new
Scanner(System.in);
System.out.print("Please
enter the number of ingredients:= ");
int numIngredients =
sc.nextInt();
sc.nextLine();
ingredients = new
String[numIngredients];
for(int
i=0;i<numIngredients;i++){
ingredients[i] = sc.nextLine();
}
}
@Override
public void prepare() {
System.out.println("DarkChocolateMocha ingredients:= ");
for(int i = 0; i<
ingredients.length; i++){
System.out.println("Ingredient " + ingredients[i]);
}
}
}
------------------------------------------
/**
*
*/
package coffee;
/**
* @author
* Coffee.java
*/
public abstract class Coffee implements HowToMakeDrink {
String type;
String storename="CoffeeBucks Cafe";
double price;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStorename() {
return storename;
}
public void setStorename(String storename)
{
this.storename =
storename;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price =
price;
}
abstract void ingredient();
}
-----------------------------------------
/**
*
*/
package coffee;
/**
* @author
* Coffee.java
*/
public abstract class Coffee implements HowToMakeDrink {
String type;
String storename="CoffeeBucks Cafe";
double price;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStorename() {
return storename;
}
public void setStorename(String storename)
{
this.storename =
storename;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price =
price;
}
abstract void ingredient();
}
--------------------------------------------------------------------
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...
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...
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 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 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 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 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,...
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....
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...
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....
Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program: Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...