/**
 * TicketSalesFactored.java
 *
 * Demonstrates the use of conditional statements.
 * See TicketSales for an unfactored version.
 *
 * Computer Science S-111
 */

import java.util.Scanner;

public class TicketSalesFactored {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);                
        System.out.print("Enter your age: ");
        int age = console.nextInt();
        
        // Since these lines are executed at the start
        // of both cases, we factor them out to 
        // before the conditional code.
        System.out.print("orchestra or balcony? ");
        String choice = console.next();            
            
        // We also need to declare price here,
        // so that it will be available everywhere 
        // we need it.
        int price;
        
        if (age < 25) {
            // handle people younger than 25
            if (choice.equalsIgnoreCase("orchestra")) {
                price = 35;
            } else {
                price = 20;
            }
        } else {
            // handle people 25 and older
            if (choice.equalsIgnoreCase("orchestra")) {
                price = 50;
            } else {
                price = 30;
            }
        }
        
        // Since this line is executed at the end of 
        // each case, we factor it out to after
        // the conditional code.
        System.out.println("The price is $" + price);
    }
}
