Write a complete Java program in a source file to be named Assignment2. java. Th
ID: 674723 • Letter: W
Question
Write a complete Java program in a source file to be named Assignment2. java. The program prints out the following menu to a user, using ' ' (tabs) and ' ' (newline), and print or print in methods of System.out: Then prompts the user: How many hamburger(s) would you like to buy? and read in the number. Then prompts the user: How many hamburger(s) would you like to buy? How many cheeseburger(s) would you like to buy? How many drinks would you like to buy? The total cost for the hamburger(s) The total cost for the cheeseburger(s) The total cost for fries The total cost for drink(s) Which item had the highest total cost The total cost for the order The total number of hamburgers, cheeseburgers, French fries, and drinks orderedExplanation / Answer
import java.io.*;
import java.util.Scanner;
class PurchaseOrder
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Welcome to the In-N-Out Burger menu:");
System.out.println("-----------------------------------------");
System.out.println("Hamburger $2.75");
System.out.println("Cheeseburger $3.25");
System.out.println("French Fries $2.50");
System.out.println("Shake & Beverage $1.50");
System.out.println();
System.out.print("How many hamburger(s) would you like to buy?: ");
int numberOfHamburgers = in.nextInt();
System.out.print("How many cheeseburgers(s) would you like to buy?: ");
int numberOfCheeseburgers = in.nextInt();
System.out.print("How many french fries would you like to buy?: ");
int numberOfFrenchFries = in.nextInt();
System.out.print("How many drinks would you like to buy?: ");
int numberOfDrinks = in.nextInt();
System.out.println();
double hBTotal = numberOfHamburgers * 2.75;
System.out.println("The total cost of the hamburger(s): "+hBTotal);
double cBTotal = numberOfCheeseburgers * 3.25;
System.out.println("The total cost of the cheeseburger(s): "+cBTotal);
double friesTotal = numberOfFrenchFries * 2.5;
System.out.println("The total cost of the fries: "+friesTotal);
double drinksTotal = numberOfDrinks * 1.5;
System.out.println("The total cost of the drink(s): "+drinksTotal);
String highestTotalCostItem = "Hamburger.";
if(cBTotal > hBTotal)
highestTotalCostItem = "Cheeseburger.";
if(friesTotal > cBTotal)
highestTotalCostItem = "French Fries.";
if(drinksTotal > friesTotal)
highestTotalCostItem = "Shake & Beverages.";
System.out.println("The item with the highest total cost: "+highestTotalCostItem);
double orderTotalCost = hBTotal + cBTotal + friesTotal + drinksTotal;
System.out.println("The total cost for the order: "+orderTotalCost);
int totalItems = numberOfHamburgers + numberOfCheeseburgers + numberOfFrenchFries + numberOfDrinks;
System.out.println("The total number of hamburgers, cheeseburgers, frenchfries, and drinks ordered: "+totalItems);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.