/*
 * RestaurantPrice2.java
 *
 * Program for computing the price of a person eating from a buffet.
 *
 * Author: S-111 Course Staff
 * Date: July 1, 2015
 */

import java.util.*;

public class RestaurantPrice2 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);

        int type = getGuestType(console);
        int price;

        if (type == 1) {
            int age = getAge(console);
            price = getChildPrice(age);
        } else {
            boolean coupon = hasCoupon(console);

            if (type == 3) {
                price = getSeniorPrice(coupon);
            } else {
                price = getAdultPrice(coupon);
            }
        }

        System.out.println();
        System.out.println("The price is $" + price + ".00");
    }

    /*
     * Asks whether the user has a discount coupon, waits on the
     * Scanner for an answer, and returns true if the user
     * answers "yes".
     */
    public static boolean hasCoupon(Scanner console) {
        System.out.print("Do you have a discount coupon (0=no, 1=yes)? ");
        int couponStatus = console.nextInt();

        return couponStatus == 1;
    }

    /*
     * Asks for the age of the child, waits on the Scanner for
     * an answer, and returns the age as an integer.
     */
    public static int getAge(Scanner console) {
        System.out.print("Enter the child's age: ");
        return console.nextInt();
    }

    /*
     * Giving the user a list of choices, this method asks the user
     * whether they are a child (1), adult (2), or senior (3). It
     * returns the user's choice.
     */
    public static int getGuestType(Scanner console) {
        System.out.println("Types of guest:");
        System.out.println("   1. child");
        System.out.println("   2. adult");
        System.out.println("   3. senior");
        System.out.println();
        System.out.print("Enter the type of guest (1-3): ");
        return console.nextInt();
    }

    /*
     * Given the age of the child, this method returns the
     * appropriate price.
     */
    public static int getChildPrice(int age) {
        if (age <= 5) {
            return 0;
        } else {
            return 15;
        }
    }

    /*
     * Given a Boolean that is true when the adult has a
     * coupon, this method returns the appropriate price.
     */
    public static int getAdultPrice(boolean withCoupon) {
        if (withCoupon) {
            return 20;
        } else {
            return 30;
        }
    }

    /*
     * Given a Boolean that is true when the senior has a
     * coupon, this method returns the appropriate price.
     */
    public static int getSeniorPrice(boolean withCoupon) {
        if (withCoupon) {
            return 10;
        } else {
            return 18;
        }
    }

}
