/** * Lab3aSolution.java - Solution to Lab3a, done in a more complex manner which expedites the process for members and children * * @author Jesse Harden * @version 1-July-2015 */ import java.util.Scanner; public class Lab3aSolution { public static void main(String[] args) { final int ADULT_PRICE = 20; final int SENIOR_PRICE = 18; final int STUDENT_PRICE = 14; final int YOUTH_PRICE = 14; final int STUDENT_MEMBERSHIP_PRICE = 40; final int NOT_STUDENT_MEMBERSHIP_PRICE = 75; final int CHILD_PRICE = 0; final int MEMBER_PRICE = 0; final int CHILD_MAX_AGE = 12; final int YOUTH_MAX_AGE = 18; final int SENIOR_MIN_AGE = 65; final int SENIOR_MAX_AGE = 140; // no supernaturally old people allowed, I guess? // I'm assuming only college-aged students get a discount // Of course, this can be changed if we want to do that //final int STUDENT_MIN_AGE = 19; // I decided to nix this part of the code and assume that the museum offers reduced entrance fee to all students. Scanner scanObj; boolean valid = true; boolean isChild = false; boolean isYouth = false; boolean isAdult = false; boolean isSenior = false; boolean isMember = false; boolean isStudent = false; boolean getMembership = false; final String INVALID_DATA = "Sorry, but you have entered an invalid response. Please reboot the program and try again."; System.out.println("Welcome to the Radford Museum of Fine Arts!"); System.out.println("How many years have you lived?"); scanObj = new Scanner(System.in); int age = scanObj.nextInt(); if (age <= CHILD_MAX_AGE && age >= 0) { isChild = true; System.out.println("Congradulations! You get in for free!\nEnjoy your time at the Radford Museum of Fine Arts!"); } else if (age > CHILD_MAX_AGE && age <= YOUTH_MAX_AGE) { isYouth = true; } else if (age > YOUTH_MAX_AGE && age < SENIOR_MIN_AGE) { isAdult = true; } else if (age >= SENIOR_MIN_AGE && age < SENIOR_MAX_AGE) { isSenior = true; } else { valid = false; System.out.println(INVALID_DATA); } if (valid == true && isChild == false) { System.out.println("Are you a member of this museum? Y or N"); scanObj = new Scanner(System.in); String areMember = scanObj.next(); if (areMember.equals("Y")) { System.out.println("Congradulations! You get in for free!\nEnjoy your time at the Radford Museum of Fine Arts!"); isMember = true; } else if (areMember.equals("N")) { System.out.println("Would you like to become a member today? Y or N"); scanObj = new Scanner(System.in); String wantMember = scanObj.next(); if (wantMember.equals("Y")) { getMembership = true; } else if (wantMember.equals("N") == false) { valid = false; System.out.println(INVALID_DATA); } } else { valid = false; System.out.println(INVALID_DATA); } if (valid == true && isMember == false) { System.out.println("Are you a student? Y or N"); scanObj = new Scanner(System.in); String areStudent = scanObj.next(); if (areStudent.equals("Y")) { isStudent = true; } else if (areStudent.equals("N") == false) { valid = false; System.out.println(INVALID_DATA); } } final String ADMISSION = "Your admission today will be $"; if (getMembership == true && valid == true) { if (isStudent) { System.out.println(ADMISSION + STUDENT_MEMBERSHIP_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } else { System.out.println(ADMISSION + NOT_STUDENT_MEMBERSHIP_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } } else if (valid == true) { if (isStudent) { System.out.println(ADMISSION + STUDENT_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } else if (isYouth) { System.out.println(ADMISSION + YOUTH_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } else if (isAdult) { System.out.println(ADMISSION + ADULT_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } else { System.out.println(ADMISSION + SENIOR_PRICE + ".\nEnjoy your time at the Radford Museum of Fine Arts!"); } } } } }