1 / 3100%
import java.util.Scanner;
import java.text.NumberFormat;
public class Assignment2
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
NumberFormat fm1 = NumberFormat.getCurrencyInstance();
System.out.println("Welcome to the In-N-Out Burger menu: "); //
This is the menu along with prices of the items.
System.out.println("-----------------------------------------");
System.out.println("\tHamburger $2.75");
System.out.println("\tCheeseburger $3.25");
System.out.println("\tFrench Fries $2.50");
System.out.println("\tShake & Beverage: $1.50");
int hamburger, cheeseburger, ff, beverage; // These will be where
the amount of each item is stored
double hamburgerTotal, cheeseburgerTotal, ffTotal,
beverageTotal; //This will be where the total cost of each item
final double HAMBURGER_PRICE = 2.75; //This is the cost of
each individual item. This amount will not change.
final double CHEESEBURGER_PRICE = 3.25;
final double FRENCH_FRIES = 2.50;
final double DRINK_PRICE = 1.50 ;
System.out.println("\nHow many hamburger(s) would you like to buy?
"); // These statements will prompt the user for each item
hamburger = scan.nextInt();
//***********************************************
// Name: Luann Nowell
// For: CSE 110 Assignment #2
// Author:
// Description: Place an order at In-N-Out Burger, calculate the totals, find
the max item purchased and get the grand total.
// Time Spent: 5 hours
// Date: September 1, 2016
//***********************************************
// Part 1
// 1. a) True
// b) False
// c) True
// d) True
// 2. Scanner scan = new Scanner(System.in);
// String fName, mName, lName;
// System.out.println("Please enter first name: ");
// fName = scan.nextLine();
// System.out.println("Please enter middle name: ");
// mName = scan.nextLine();
// System.out.println("Please enter last name: ");
// lName = scan.nextLine();
//
// System.out.println("" + fName + mName + lName);
// 3. Hy
//******************************************************************************
***************************************
System.out.print("How many cheeseburger(s) would you like to buy?
");
cheeseburger = scan.nextInt();
System.out.print("How many French fries would you like to buy? ");
ff = scan.nextInt();
System.out.print("How many drinks would you like to buy? ");
beverage = scan.nextInt();
hamburgerTotal = hamburger * HAMBURGER_PRICE; //The total cost
is calculated by multiplying the total amount of each item by it's individual
amount
System.out.println("The total cost for the hamburger(s) " +
fm1.format(hamburgerTotal));
cheeseburgerTotal = cheeseburger * CHEESEBURGER_PRICE;
System.out.println("The total cost for the cheeseburger(s) " +
fm1.format(cheeseburgerTotal));
ffTotal = ff * FRENCH_FRIES;
System.out.println("The total cost for the fries " +
fm1.format(ffTotal));
beverageTotal = beverage * DRINK_PRICE;
System.out.println("The total cost for the drink(s) " +
fm1.format(beverageTotal));
// below is determining which has the greatest cost, by comparing each item
if (hamburgerTotal > cheeseburgerTotal && hamburgerTotal > ffTotal
&& hamburgerTotal > beverageTotal)
System.out.println("\nThe hamburgers had the highest cost.");
else
if (cheeseburgerTotal> ffTotal&&cheeseburgerTotal>
hamburgerTotal&&cheeseburgerTotal> beverageTotal)
{
System.out.println("\nThe cheeseburgers had the highest
cost.");
}
else
if (ffTotal> beverageTotal&&ffTotal> hamburgerTotal&&ffTotal>
cheeseburgerTotal)
{
System.out.println("\nThe french fries had the
highest cost.");
}
else
if (beverageTotal> hamburgerTotal&&beverageTotal>
cheeseburgerTotal&&beverageTotal> ffTotal)
{
System.out.println("\nThe drinks had the
highest cost.");
}
System.out.println("\nTotal cost for your order " +
fm1.format(hamburgerTotal+cheeseburgerTotal+ffTotal // Here we are determining
the total cost of the order
+beverageTotal));
System.out.println("\nTotal number of items ordered " +
(hamburger+cheeseburger+ff // Here we are listing the total amount of items
purchased.
+beverage));
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed