Write an application that displays a menu of three items for the Jivin’ Java Cof
ID: 3677463 • Letter: W
Question
Write an application that displays a menu of three items for the Jivin’ Java CoffeeShop as follows:
(1) American 1.99
(2) Espresso 2.50
(3) Latte 2.15
Prompt the user to choose an item using the number (1, 2, or 3) that corresponds to the item, or to enter 0 to quit the application. After the user makes the first selection, if the choice is 0, display a total bill of $0. Otherwise, display the menu again. The user should respond to this prompt with another item number to order or 0 to quit. If the user types 0, display the cost of the single requested item. If the user types 1, 2, or 3, add the cost of the second item to the first, and then display the menu a third time. If the user types 0 to quit, display the total cost of the two items; otherwise, display the total for all three selections. Save the file as Coffee.java.
Explanation / Answer
Java code:
import java.util.Scanner;
public class Coffee
{
//private static double orderStop;
private static int item;
private static double price;
private static Scanner keyboard;
private static int menuNo;
public static void main(String[] args) {
// TODO Auto-generated method stub
price = price += service();
if (menuNo >0 || menuNo < 4)
{
price = service();
}
else
if (menuNo == 0)
{
System.out.println("Number of purchases " + item + "."
+ " Your total is $" + price + "." );
}
else
{
System.out.println("Sorry. An error has occured with your order" );
}
}
public static double service()
{
//int menuNo;
System.out.println("Jivin’ Java CoffeeShop");
System.out.println("MENU");
System.out.println("(1) American $1.99");
System.out.println("(2) Espresso $2.50");
System.out.println("(3) Latte $2.15");
keyboard = new Scanner(System.in);
System.out.println("Please place your order. "
+ " Enter 1 for American, "
+ " 2 for Espresso, "
+ " 3 for Latte "
+ " or "
+ " 0 to complete and total your order.");
menuNo = keyboard.nextInt();
if(menuNo == 1)
{
//orderStop = 0;
item += 1;
price +=1.99;
return 1.99;
}
else
if(menuNo == 2)
{
//orderStop = 0;
item += 1;
price += 2.50;
return 2.50;
}
else
if(menuNo == 3)
{
//orderStop = 0;
item += 1;
price += 2.15;
return 2.15;
}
else
//orderStop += 1;
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.