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 = false; System.out.println(""); System.out.println("Invalid Month"); System.exit(1); } if (month == 3 & (day < 1 || day > 31)) { daytest = false; System.out.println(""); System.out.println("Invalid Day"); System.exit(1); } if (month == 4 & (day < 1 || day > 30)) { daytest = false; System.out.println(""); System.out.println("Invalid Day"); System.exit(1); } if (month == 5 & (day < 1 || day > 15)) { daytest = false; System.out.println(""); System.out.println("Invalid Day"); System.exit(1); } 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 > 0 & DayOfWeek < 1) || DayOfWeek > 4) { monThurs = false; } 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; int studentprice = price; 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; } if (isWeekday(month,day) == false) { price = price + 3; } if (isMatinee == true) { studentprice = (price); } else if (isMatinee == false) { studentprice = (price - 2); } int cost = (price * numberOfAdultTickets) + (numberOfStudentTickets * studentprice); return cost; } public static void main (String[] args) { Scanner console = new Scanner(System.in); System.out.println(""); System.out.println(""); System.out.println("Welcome to the Wolfpack Theater Box Office!"); System.out.println(""); 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("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)"); String matinee = console.next(); System.out.println("How many adult movie tickets?"); int adult = console.nextInt(); System.out.println("How many student movie tickets?"); int student = console.nextInt(); System.out.println("Movie (C-aptain Phillips, G-ravity, P-hilomena): " + movie); if (isValidDate(monthInput, dayInput) == true) { System.out.println("Month: " + monthInput); System.out.println("Day: " + dayInput); } boolean isMatinee2 = true; if (matinee == "y" || (matinee == "Y")) { isMatinee2 = true; } else { isMatinee2 = false; } System.out.println("Matinee: " + matinee); System.out.println("Cost of Tickets: $" + getCost(movie, monthInput, dayInput, isMatinee2, adult, student)); } }