Write a program that demonstrates the skills you’ve learned throughout this quar
ID: 3574903 • Letter: W
Question
Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of project offers only a few guidelines and requirements, allowing you to invest as much time, effort and imagination as you want.
You are hired to develop a program for a client who described what he wants using the following scenario:
“I like to drink a beverage every morning. This might be a cup of coffee or tea. If it is coffee, I like to choose (based on wake up time) b/w espresso (short or long) or latte with one or two shots of espresso, no foam, and extra hot. If it is tea, I like to have either green or black tea; the latter can be with lemon or with half and half and sugar, depending of the kind of tea. I have a large collection of coffee and tea capsules and my beverage machine could be programmed (in Java) to make a drink at the specified time.
I would like to have a program which will allow me to set up at evening my coming morning drink. Sometimes, I order my beverage from my neighborhood coffee shop specifying a pick up time .”
You manager and you agreed on the following specs on what the solution will look like:
Interactive: ask for options using UI (keyboard /Scanner or speech recognition =) ) and print out (screen) the choice
Store data in files (read from; write to .... )
Modular: use several classes and various method
Use test cases (aka have a driver / main)
Define preconditions and postconditions
Handle exceptions
Use default values for your variables
Use arrays (many kinds of coffee, tea, milk, ...) for your data Comment and Document
Explanation / Answer
package nucleus;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class TeaCoffee
{
private static String[] bevarages = {"Tea","Coffee"};
private static String[] typesCoffee = {"espresso","latte"};
public static void main(String args[]) throws IOException
{
String selectedTea = null;
String selectedDrink = null;
String selectedDrinkDetails = null;
Scanner scan = new Scanner(System.in);
System.out.println("What would you like to have tomorrow?");
System.out.println("Select 1 for tea and 2 for coffee");
int choice = scan.nextInt();
BufferedReader br = new BufferedReader(new FileReader("tea_type.txt"));
if(choice>=2)
{
System.out.println("Please select correct choice of drink.");
}
else
{
selectedDrink = bevarages[choice-1];
switch(choice)
{
case 1:
System.out.println("Which coffee would you like to have?");
System.out.print("Select ");
String line = br.readLine();
int i = 0;
while(line != null)
{
System.out.print(" "+ i++ +" "+line +" ");
}
System.out.println();
choice = scan.nextInt();
selectedTea = typesCoffee[choice-1];
if(selectedTea.equalsIgnoreCase("Black"))
{
System.out.println("What would you like to have in black tea?");
System.out.print("Select 1. for lemon 2. for sugar and lemon");
System.out.println();
choice = scan.nextInt();
if(choice ==1)
{
selectedDrinkDetails = " with lemon";
}
else if(choice==2)
{
selectedDrinkDetails = " with lemon and sugar.";
}
else
selectedDrinkDetails = "invalid option";
}
break;
case 2 :
System.out.println("Which coffee would you like to have?");
System.out.println("Select 1 for espresso and 2 for latte");
choice = scan.nextInt();
selectedTea = typesCoffee[choice-1];
if(selectedTea.equalsIgnoreCase("latte"))
{
System.out.println("How much shots of espresso would you like to have?");
System.out.print("Select 1. for one shot 2. for two shot");
System.out.println();
choice = scan.nextInt();
if(choice ==1)
{
selectedDrinkDetails = " one shot espresso.";
}
else if(choice==2)
{
selectedDrinkDetails = " two shot espresso.";
}
else
{
selectedDrinkDetails = "invalid option";
}
}
else if(selectedTea.equalsIgnoreCase("espresso"))
{
System.out.println("How much quantity of espresso would you like to have?");
System.out.print("Select 1. for short 2. for long");
System.out.println();
choice = scan.nextInt();
if(choice ==1)
{
selectedDrinkDetails = " Short.";
}
else if(choice==2)
{
selectedDrinkDetails = " Long.";
}
else
{
selectedDrinkDetails = "invalid option";
}
}
break;
}
System.out.println("You have selcted "+selectedTea +" "+selectedDrink+" with"+selectedDrinkDetails);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.