import java.util.*; //so that I can use Scanner public class BoxOffice { public static final int YEAR = 2014; //Return true if the date is a valid date between March 1 and May 15 //Return false otherwise public static boolean isValidDate (int month, int day){ boolean monthtest = true; boolean daytest = true; boolean ValidDateTest = true; if (month < 3 & month > 5) { monthtest = !monthtest; System.out.println(""); System.out.println("Invalid Input"); System.exit(1); } if (month == 3 & (day < 1 || day > 31)) { daytest = !daytest; System.out.println(""); System.out.println("Invalid Input"); System.exit(1); } if (month == 4 & (day < 1 || day > 30)) { daytest = !daytest; System.out.println(""); System.out.println("Invalid Input"); System.exit(1); } if (month == 5 & (day < 1 || day > 15)) { daytest = !daytest; System.out.println(""); System.out.println("Invalid Input"); System.exit(1); } if (monthtest == false && daytest == false) { ValidDateTest = !ValidDateTest; } else { System.out.println("Month: " + month); System.out.println("Day: " + day); } return ValidDateTest; } //This method must use Zeller's algorithm described below. //Use 2014 as the year -- make this a class constant! //You may assume the month and day are valid //Return true if date falls on Monday through Thursday //Return false if date falls on Friday through Sunday public static boolean isWeekday (int month, int day) { boolean monThurs = true; int w = YEAR - (14 - month) / 12; int x = w + w / 4 - w / 100 + w / 400; int z = month + 12 * ((14 - month) / 12) - 2; int DayOfWeek = (day + x + (31 * z) / 12) % 7; if (DayOfWeek < 1 & DayOfWeek > 4) { monThurs = !monThurs; } return monThurs; } //Return cost of tickets //Throws an IllegalArgumentException if movie and/or date is/are invalid or number of tickets < 0 public static int getCost (char movie, int month, int day, boolean isMatinee, int numberOfAdultTickets, int numberOfStudentTickets) { int price = 8; if ((Character.toLowerCase(movie) == 'p' || Character.toLowerCase(movie) == 'g') && isMatinee == true) { price = price - 2; } else if ((Character.toLowerCase(movie) == 'p' || Character.toLowerCase(movie) == 'g') && isMatinee == false) { price = price; } if ((Character.toLowerCase(movie) == 'c') && isMatinee == true) { price = price; } else if ((Character.toLowerCase(movie) == 'c') && isMatinee == false) { price = price + 2; } return price; } public static void main (String[] args) { Scanner console = new Scanner(System.in); System.out.println(""); System.out.println("Welcome to the Wolfpack Theater Box Office!"); System.out.println(""); System.out.println("When prompted, please enter the movie you would like see:"); System.out.println("C (C-aptain Phillips), G (G-ravity), or P (P-hilomena)."); System.out.println("Also, enter the date, whether it is a matinee, the number of adults, and"); System.out.println("the number of student tickets you would like to purchase."); System.out.println(" The total cost of the tickets will then be displayed."); System.out.println(""); System.out.println("What movie would you like to see? (C, G, or P)"); char movie = console.next().charAt(0); System.out.println(""); System.out.println("What number month would you like to see it? (3,4,5)"); int monthInput = console.nextInt(); System.out.println("What day of the month would you like to see it? (1-31 for month 3, 1-30 for month 4, 1-15 for month 5)"); int dayInput = console.nextInt(); System.out.println("Matinee? (Y/N)"); char matinee = console.next().charAt(0); System.out.println("How many adult movie tickets?"); int adult = console.nextInt(); System.out.println("How many child movie tickets?"); int child = console.nextInt(); isValidDate(monthInput, dayInput); //if (ValidDateTest = true) { //System.out.println("Month: " + monthInput); //System.out.println("Day: " + dayInput); // isWeekday(monthInput, dayInput); boolean isMatinee = true; if (matinee != 'y' || (matinee != 'Y')) { isMatinee = !isMatinee; } getCost(movie, monthInput, dayInput, isMatinee, adult, child); System.out.println("Cost of Tickets: " + price); } }