Advertisement
Guest User

Fast-food

a guest
Dec 12th, 2023
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class order{
  4.     public static void main(String[] args){
  5.         char choice;
  6.  
  7.         Scanner unit = new Scanner(System.in);
  8.  
  9.         System.out.print("Welcome to a Generic Fast Food Restaurant. What would you like to order?");
  10.  
  11.         do{
  12.             System.out.print( "\n\n1. Hamburger - $0.78"
  13.             + "\n2. Cheeseburger - $1.13"
  14.             + "\n3. Frenchfries - $0.97"
  15.             + "\n4. Fried Chicken - $1.75"
  16.             + "\n5. Chicken Nuggets - $2.17"
  17.             + "\n6. Hotcakes - $1.46"
  18.             + "\nPlease type the number of the order you want"
  19.             + "\n\n>> ");
  20.             int order = unit.nextInt();
  21.  
  22.             double total = calculateTotal(order);
  23.  
  24.             System.out.print("\nYour change is " + total + ". Thank you for ordering with a Generic Fast Food Restaurant."
  25.             + "\nWould you like to place another order? (Y/N) >> ");
  26.             choice = unit.next().charAt(0);
  27.        
  28.         }while (choice == 'Y' || choice == 'y');
  29.  
  30.         System.out.println("Thank you for ordering with a Generic Fast Food Restaurant. Goodbye!");
  31.     }
  32.  
  33.     public static double calculateTotal(int order) {
  34.  
  35.         Scanner unit = new Scanner(System.in);
  36.  
  37.         double drink = 1.32;
  38.         double cost = 0.0;
  39.         double itemCost = 0.0;
  40.  
  41.         switch (order) {
  42.             case 1:
  43.                 itemCost = 0.78;
  44.                 break;
  45.             case 2:
  46.                 itemCost = 1.13;
  47.                 break;
  48.             case 3:
  49.                 itemCost = 0.97;
  50.                 break;
  51.             case 4:
  52.                 itemCost = 1.75;
  53.                 break;
  54.             case 5:
  55.                 itemCost = 2.17;
  56.                 break;
  57.             case 6:
  58.                 itemCost = 1.46;
  59.                 break;
  60.             default:
  61.                 System.out.print("\nInvalid Command. Please only choose one");
  62.         }
  63.  
  64.         System.out.print("Would you like to add a drink to your order for only $1.32? >> ");
  65.         char choice = unit.next().charAt(0);
  66.  
  67.         if (choice == 'Y' || choice == 'y') {
  68.             cost = itemCost + drink;
  69.         } else {
  70.             cost = itemCost;
  71.         }
  72.  
  73.         System.out.print("Thank you for ordering your total is " + cost + "\n How much are you paying? >> ");
  74.         double money = unit.nextDouble();
  75.  
  76.         return money - cost;
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement