25% found this document useful (8 votes)
18K views

Simple Java Restaurant Menu

This Java code is for a restaurant menu ordering program that allows customers to select menu items, calculates subtotals and taxes, and outputs a final receipt. It imports necessary libraries, declares variables to track selections and counts, contains a do-while loop to continually prompt for selections until the user chooses to finish their order, performs calculations after each selection, and finally displays a summary of the order including item counts, subtotal, taxes, and total.

Uploaded by

Izaac Garcilazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
25% found this document useful (8 votes)
18K views

Simple Java Restaurant Menu

This Java code is for a restaurant menu ordering program that allows customers to select menu items, calculates subtotals and taxes, and outputs a final receipt. It imports necessary libraries, declares variables to track selections and counts, contains a do-while loop to continually prompt for selections until the user chooses to finish their order, performs calculations after each selection, and finally displays a summary of the order including item counts, subtotal, taxes, and total.

Uploaded by

Izaac Garcilazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.text.

DecimalFormat;
import java.util.Scanner;
public class Homework4 {
public static void main(String[] args) {
//setup
Scanner input= new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
double subTotal= 0;
double total =0;
int Selection=0;
int cevicheCount=0;
int soupCount=0;
int steakCount=0;
int beerCount=0;
int wineCount=0;
double ceviche=9.45;
double soup=7.95;
double steak=19.95;
double beer=3.95;
double wine=3.95;
int itemsNumber = 0;
double tax = 0;
double taxes = 0.10;
double totalFinal = 0;

do {
// input
System.out.println("Welcome to Mixtura");
System.out.println(" 1) Ceviche $" + ceviche);
System.out.println(" 2) Chichen Soup $" + soup);
System.out.println(" 3) Steak with fries $" + steak);
System.out.println(" 4) Beer $" + beer);
System.out.println(" 5) Wine $" + wine);
if (Selection !=0){
System.out.println(" 0) Finish Order");
}
System.out.println ("Current Subtotal $" + (df.format(total)));
System.out.print("Please make your selection: ");
Selection = input.nextInt();
// computation
if (Selection > 5 || Selection <0){
System.out.println("No such a choice. Please enter a different choic
e");
}else if (Selection == 1){
subTotal = ceviche;
++cevicheCount;
++itemsNumber;
total = total + subTotal;

}
if (Selection == 2){
subTotal = soup;
++soupCount;
++itemsNumber;
total = total + subTotal;
}
if (Selection == 3){
subTotal = steak;
++steakCount;
++itemsNumber;
total = total + subTotal;
}
if (Selection == 4){
subTotal = beer;
++beerCount;
++itemsNumber;
total = total + subTotal;
}
if (Selection == 5){
subTotal = wine;
++wineCount;
++itemsNumber;
total = total + subTotal;
}
}while (Selection !=0);
// final output
tax = (total*taxes);
totalFinal = total+tax;
if (cevicheCount != 0){
System.out.println(cevicheCount+" Ceviches");
}if (soupCount != 0){
System.out.println(soupCount+" Chicken Soups");
}if (steakCount !=0){
System.out.println(steakCount+" Steaks with fries");
}if (beerCount !=0){
System.out.println(beerCount+" Bottles of Beer");
}if (wineCount !=0){
System.out.println(wineCount+" Glasses of Wine");
}
System.out.println("Order: " + itemsNumber +" Items");
System.out.println("Subtotal: $" + (df.format(total)));
System.out.println("Tax (10%): $"+ (df.format(tax)));
System.out.println("Total: $ " + (df.format(totalFinal)));
System.out.println("Thank you. Please come again!");

}
}

You might also like