/**
 * TicketSalesExtendedFactoredWithMethods.java
 *
 * Demonstrates the use of conditional statements.
 * This version builds on TicketSalesExtendedFactored, and it
 * uses separate methods to capture the structure of the program
 *
 * Computer Science S-111
 */

import java.util.Scanner;

public class TicketSalesExtendedFactoredWithMethods {
    /*
     * discountPrice - takes the user's choice for type of seat
     * and returns the discounted price for that type of seat.
     */
    public static int discountPrice(String choice) {
        // We need to give this method its own
        // price variable, because the one declared in main
        // is not in scope here.
        int price;
        
        if (choice.equalsIgnoreCase("orchestra")) {
            price = 35;
        } else {
            price = 20;
        }
        
        return price;
    }

    /*
     * regularPrice - takes the user's choice for type of seat
     * and returns the regular price for that type of seat.
     */
    public static int regularPrice(String choice) {
        // Rather than using a variable called price,
        // we use two different return statements.
        if (choice.equalsIgnoreCase("orchestra")) {
            return 35;
        } else {
            return 20;
        }
    }
    
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);                
        System.out.print("Enter your age: ");
        int age = console.nextInt();
        
        if (age < 13) {
            System.out.println("You cannot buy a ticket.");
        } else {
            System.out.print("orchestra or balcony? ");
            String choice = console.next();            
            
            int price;
            if (age < 25) {
                price = discountPrice(choice);
            } else {
                price = regularPrice(choice);
            }
        
            System.out.println("The price is $" + price);
        }
    }
}
