
import java.util.Scanner;

/**
 * A simple order-taking app to demonstrate the "if" control and boolean 
 * methods. With more methods than the GreesieBurger program.
 *
 * @author Mark Young (A00000000)
 */

public class BooleanMethods {

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

        // welcome customer
        System.out.print("\n\n"
                + "Welcome to GreesieBurger!\n"
                + "-------------------------\n\n");

        // ask for sandwich order
        System.out.print("What sandwich would you like? ");
        addToOrder(kbd.nextLine());
        amount += 8.95;

        // ask if want fries
        if (userConfirms("Would you like fries with that? ")) {
            addToOrder("Fries");
            amount += 2.99;
        }

        // ask for drink order
        System.out.print("What can I get you to drink? ");
        answer = kbd.nextLine();

        // check if we carry that
        while (!answer.toUpperCase().equals("PEPSI")) {
            System.out.println("No " + answer + ".  Pepsi.");
            System.out.print("What can I get you to drink? ");
            answer = kbd.nextLine();
        }
        addToOrder(answer);
        amount += 2.99;

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

    /**
     * Add an item to the order by "shouting" to the back, and waiting for the
     * person on grill to confirm by repeating the item.
     *
     * @param item the item to add to the order
     */
    private static void addToOrder(String item) {
        System.out.println(item.toUpperCase() + "!");
        System.out.println("(" + item.toLowerCase() + ")");
    }

    /**
     * Ask the user a yes-no question and return whether they say yes.
     * Make sure that their answer is either a yes or a no before returning.
     *
     * @param prompt the question to ask
     * @return whether the (final) answer counts as a "yes"
     */
    private static boolean userConfirms(String prompt) {
        // create variables
        Scanner kbd = new Scanner(System.in);
        String answer;

        // get answer
        System.out.print(prompt + " ");
        answer = kbd.next();
        kbd.nextLine();

        // make sure it's a yes or a no
        while (!isYes(answer) && !isNo(answer)) {
            System.out.println("Please answer YES or NO.");
            System.out.print(prompt + " ");
            answer = kbd.next();
            kbd.nextLine();
        }

        // return whether it's a yes
        return isYes(answer);
    }

    /**
     * Check a word to see if it counts as a "yes".
     *
     * @param word the word to check
     * @return whether the word counts as a "yes"
     */
    private static boolean isYes(String word) {
        return word.equalsIgnoreCase("yes")
            || word.equalsIgnoreCase("yeah")
            || word.equalsIgnoreCase("yup")
            || word.equalsIgnoreCase("sure")
            || word.equalsIgnoreCase("ok")
            || word.equalsIgnoreCase("fine");
    }

    /**
     * Check a word to see if it counts as a "no".
     *
     * @param word the word to check
     * @return whether the word counts as a "no"
     */
    private static boolean isNo(String word) {
        return word.equalsIgnoreCase("no")
            || word.equalsIgnoreCase("nope")
            || word.equalsIgnoreCase("nah");
    }

}

