Source of GreesieBurger.java


  2: import java.util.Scanner;

  4: /**
  5:  * A simple order-taking app to demonstrate the "if" control
  6:  *
  7:  * @author Mark Young (A00000000)
  8:  * @version 1.1 2014-09-08
  9:  */
 10: public class GreesieBurger {

 12:     public static void main(String[] args) {
 13:         // create variables
 14:         Scanner kbd = new Scanner(System.in);
 15:         String answer;
 16:         double amount = 0.00;

 18:         // welcome customer
 19:         System.out.print("\n\n"
 20:                 + "Welcome to GreesieBurger!\n"
 21:                 + "-------------------------\n\n");

 23:         // ask for sandwich order
 24:         System.out.print("What sandwich would you like? ");
 25:         answer = kbd.nextLine();
 26:         System.out.println(answer.toUpperCase() + "!");
 27:         System.out.println("(" + answer.toLowerCase() + ")");
 28:         amount += 8.95;

 30:         // ask if want fries
 31:         System.out.print("Would you like fries with that? ");
 32:         answer = kbd.next();
 33:         kbd.nextLine();
 34:         while (!answer.equalsIgnoreCase("yes") 
 35:                 && !answer.equalsIgnoreCase("no")) {
 36:             System.out.println("Please answer YES or NO.");
 37:             System.out.print("Would you like fries with that? ");
 38:             answer = kbd.next();
 39:             kbd.nextLine();
 40:         }
 41:         if (answer.equalsIgnoreCase("yes")) {
 42:             System.out.println("FRIES!");
 43:             System.out.println("(fries)");
 44:             amount += 2.99;
 45:         }

 47:         // ask for drink order
 48:         System.out.print("What can I get you to drink? ");
 49:         answer = kbd.nextLine();
 50:         while (!answer.equalsIgnoreCase("Pepsi")) {
 51:             System.out.println("No " + answer + ". Pepsi.");
 52:             System.out.print("What can I get you to drink? ");
 53:             answer = kbd.nextLine();
 54:         }
 55:         System.out.println(answer.toUpperCase() + "!");
 56:         System.out.println("(" + answer.toLowerCase() + ")");
 57:         amount += 2.99;

 59:         // report back order and total amount owed
 60:         System.out.print("\n"
 61:                 + "That'll be $" + amount + ".\n\n");
 62:         System.out.println("Thank-you for eating at GreesieBurgers!\n");
 63:     }

 65: }