Source of GreesieBurger.java


  2: import java.util.Scanner;

  4: /**
  5:  * A simple order-taking app to demonstrate the "if" control and boolean 
  6:  * methods.
  7:  *
  8:  * @author Mark Young (A00000000)
  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:         Utilities.printTitle("Welcome to GreesieBurger!");
 20:         // System.out.print("\n\n"
 21:                 // + "Welcome to GreesieBurger!\n"
 22:                 // + "-------------------------\n\n");

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

 31:         // ask if want fries
 32:         System.out.print("Would you like fries with that? ");
 33:         answer = kbd.next();
 34:         kbd.nextLine();
 35:         while (!meansYes(answer) && !meansNo(answer)) {
 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 (meansYes(answer)) {
 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:         System.out.println(answer.toUpperCase() + "!");
 51:         System.out.println("(" + answer.toLowerCase() + ")");
 52:         amount += 2.99;

 54:         // report back order and total amount owed
 55:         System.out.print("\n"
 56:                 + "That'll be $" + amount + ".\n\n");
 57:         System.out.println("Thank-you for eating at GreesieBurgers!\n");
 58:     }

 60:     /**
 61:      * Check a word to see if it counts as a "yes".
 62:      *
 63:      * @param word the word to check
 64:      * @return whether the word counts as a "yes"
 65:      */
 66:     private static boolean meansYes(String word) {
 67:         return word.equalsIgnoreCase("yes")
 68:             || word.equalsIgnoreCase("yeah")
 69:             || word.equalsIgnoreCase("yup")
 70:             || word.equalsIgnoreCase("sure")
 71:             || word.equalsIgnoreCase("ok")
 72:             || word.equalsIgnoreCase("fine");
 73:     }

 75:     /**
 76:      * Check a word to see if it counts as a "no".
 77:      *
 78:      * @param word the word to check
 79:      * @return whether the word counts as a "no"
 80:      */
 81:     private static boolean meansNo(String word) {
 82:         return word.equalsIgnoreCase("no")
 83:             || word.equalsIgnoreCase("nope")
 84:             || word.equalsIgnoreCase("nah");
 85:     }

 87: }