import java.util.Scanner;

public class RestaurantPicker
{
    private String[] locations;
    private String[] restaurantNames;
    private String[] restaurantLocations;
    private int[] restaurantPriceRanges;
    private Scanner fromKeyboard;

    public static void main(String[] args)
    {
        RestaurantPicker picker = new RestaurantPicker();
        picker.runOnce();
    }

    public RestaurantPicker()
    {
        locations = new String[]{"Magic Kingdom", "EPCOT"};

        restaurantNames = new String[]{
                "Aloha Isle",
                "Casey's Corner",
                "The Plaza Restaurant",
                "The Diamond Horseshoe",
                "Be Our Guest Restaurant",
                "Connections Eatery",
                "La Hacienda de San Angel",
                "Le Cellier Steakhouse",
                "Monsieur Paul",
                "Cinderella's Royal Table",
                "The Crystal Palace",
                "Space 220"
        };

        restaurantLocations = new String[]{
                "Magic Kingdom",
                "Magic Kingdom",
                "Magic Kingdom",
                "Magic Kingdom",
                "Magic Kingdom",
                "EPCOT",
                "EPCOT",
                "EPCOT",
                "EPCOT",
                "Magic Kingdom",
                "Magic Kingdom",
                "EPCOT"
        };

        restaurantPriceRanges = new int[]{1, 1, 2, 3, 4, 1, 2, 3, 4, 4, 4, 4};

        fromKeyboard = new Scanner(System.in);
    }

    public String getLocation()
    {
        for(int i = 0; i < locations.length; i++)
            System.out.println((i + 1) + ": " + locations[i]);

        System.out.print("Location number: ");
        int locationNum = asInt(fromKeyboard.nextLine(), -1);

        while(locationNum < 1 || locationNum > locations.length)
        {
            System.out.println("Invalid location number");
            System.out.print("Location number: ");
            locationNum = asInt(fromKeyboard.nextLine(), -1);
        }

        return locations[locationNum - 1];
    }

    public int getPriceRange()
    {
        System.out.println("1: $14.99 and under per adult");
        System.out.println("2: $15 to $34.99 per adult");
        System.out.println("3: $35 to $59.99 per adult");
        System.out.println("4: over $60 per adult");

        System.out.print("Price range: ");
        int priceRange = asInt(fromKeyboard.nextLine(), -1);

        while(priceRange < 1 || priceRange > 4)
        {
            System.out.println("Invalid price range");
            System.out.print("Price range: ");
            priceRange = asInt(fromKeyboard.nextLine(), -1);    
        }

        return priceRange;
    }

    public void printMatchingRestaurants(String location, int priceRange)
    {
        for(int i = 0; i < restaurantNames.length; i++)
        {
            if(restaurantLocations[i].equals(location) &&
                    restaurantPriceRanges[i] == priceRange)
            {
                System.out.println(restaurantNames[i]);
            }
        }
    }

    public void runOnce()
    {
        String location = getLocation();

        System.out.println();
        int priceRange = getPriceRange();

        System.out.println();
        printMatchingRestaurants(location, priceRange);
    }

    public static int asInt(String str, int valueIfNotInt)
    {
        try
        {
            return Integer.parseInt(str);
        }
        catch(NumberFormatException e)
        {
            return valueIfNotInt;
        }
    }
}
