import java.text.*; import java.util.*; public class University_Apartment { public static void main (String[]arguments) { String studentName, studentID, passportNumber; String userInputMain, userInput1,userInput2, userInput3, userChoiceA, userChoiceFull, userChoiceFullA, apartmentType, register; String inputView1; String currentDate, assignDate, currentHour; char optionMain, optionInput1, optionInput2, optionInput3, optionChoiceA, optionChoiceFull, optionChoiceFullA, choiceView1; int index, index1, index2, houseNumber, roomNumber, ID; final int apartTypeA = 2; final int apartTypeB = 2; final int roomA = 2; final int roomB = 3; boolean next = false; boolean next1 = false; String [] apartmentA = { "FloorA1", "FloorA2"}; String [] apartmentB = { "FloorB1", "FloorB2"}; int[] FloorA1 = new int[apartTypeA]; int[] FloorA2 = new int[apartTypeA]; int[] FloorB1 = new int[apartTypeB]; int[] FloorB2 = new int[apartTypeB]; int[] HouseA1 = new int[roomA]; int[] HouseA2 = new int[roomA]; int[] HouseB1 = new int[roomB]; int[] HouseB2 = new int[roomB]; Scanner keyboard = new Scanner (System.in); do { System.out.println("+++++++++++++++++++++++++++++++++"); System.out.println("Fortes Fortuna Apartment"); System.out.println("+++++++++++++++++++++++++++++++++"); System.out.println("Main Menu"); System.out.println("---------------------------------"); System.out.println("I - to Apartment Info"); System.out.println("R - to Register New Student"); System.out.println("V - to View Occupancy"); System.out.println("Q - to Quit the system"); userInputMain = keyboard.nextLine(); optionMain = userInputMain.charAt(0); switch(optionMain) { case 'i' : case 'I': System.out.println(" APARTMENT INFORMATION"); System.out.println("---------------------------------"); System.out.println("A - Info Apartment A"); System.out.println("B - Info Apartment B"); System.out.println("M - to return to Main Menu"); System.out.print("Enter : "); userInput1 = keyboard.nextLine(); optionInput1 = userInput1.charAt(0); if(optionInput1 == 'M' || optionInput1 == 'm') { System.out.println(); System.out.println("Back to Main Menu."); System.out.println(); } else if(optionInput1 == 'A' || optionInput1 == 'a') { System.out.println("+++++++++ Apartment Type A +++++++++++"); System.out.println("2 bedrooms"); System.out.println("Equipped with kitchen and laundry facilities"); System.out.println("Monthly rental = RM300."); System.out.println(" M - Return to main menu"); } else if (optionInput1 == 'B' || optionInput1 == 'b') { System.out.println("+++++++++ Apartment Type B +++++++++++"); System.out.println("2 normal bedrooms + 1 master bedroom"); System.out.println("Without kitchen and laundry"); System.out.println("Monthly rental = RM200"); System.out.println("*Master bedroom attached with inside bathroom"); System.out.println("**People who live in master bedroom will be paying 40% more = RM280"); } case 'r': case 'R': System.out.println(" Register New Student"); System.out.println("---------------------------------"); System.out.println("Enter your name :"); studentName = keyboard.nextLine(); System.out.println("Enter your Student ID :"); studentID = keyboard.nextLine(); System.out.println("Enter your Passport Number :"); passportNumber = keyboard.nextLine(); System.out.println("Which apartment type you want? (A/B)"); userInput2 = keyboard.nextLine(); optionInput2 = userInput2.charAt(0); switch(optionInput2) { case 'A': apartmentA: for (index = 0; index <=apartmentA.length; index++) { if (index == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } break;} else if (FloorA1[index] < 1){ System.out.println("What floor do you want? (1/2)"); userInput3 = keyboard.nextLine(); optionInput3 = userInput3.charAt(0); switch(optionInput3) { case '1': apartmentType = "Apartment Type A"; for (index1 = 0; index1 <=FloorA1.length; index1++) { if (index1 == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } else if (FloorA1[index1] < 1){ System.out.println("Please choose house"); System.out.println("C - choose house number"); System.out.println("R - pick a random house"); System.out.print("Enter your choice = "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'c' || optionChoiceA == 'C'){ System.out.print("Enter house number you want (1/2)= "); houseNumber = keyboard.nextInt(); if ((houseNumber >= 1) && (houseNumber <= 2)) { if(FloorA1[houseNumber-1] == 0 ) { FloorA1[houseNumber-1] += 1; System.out.println("Enter room number you want(1-2)= "); roomNumber = keyboard.nextInt(); if ((roomNumber >= 1) && (roomNumber <= 2)) { if (HouseA1[roomNumber-1] == 0 ) { HouseA1 [roomNumber-1] += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } else { next1 = false; System.out.println(); System.out.println("Sorry, this room is already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFullA = keyboard.nextLine(); optionChoiceFullA = userChoiceFullA.charAt(0); if (optionChoiceFullA == 'm' || optionChoiceFullA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFullA == 'q' || optionChoiceFullA == 'Q'){ System.exit(0); } break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next1 = false; break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } } else { next = false; System.out.println(); System.out.println("Sorry, these rooms are already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFull = keyboard.nextLine(); optionChoiceFull = userChoiceFull.charAt(0); if (optionChoiceFull == 'm' || optionChoiceFull == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFull == 'q' || optionChoiceFull == 'Q'){ System.exit(0); } break; } } else if (optionChoiceA == 'r' || optionChoiceA == 'R') { for ( index1 = 0; index1 < 2 ; index1++ ) { if (FloorA1[index1] == 0 ) { FloorA1[index1] += 1; houseNumber = index1; houseNumber += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } } } else { System.out.println(); System.out.println("Invalid choice"); System.out.println("Back to Main Menu"); System.out.println(); next = false; break; } } } break; case '2': apartmentType = "Apartment Type A"; for (index1 = 0; index1 <=FloorA2.length; index1++) { if (index1 == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } else if (FloorA2[index1] < 1){ System.out.println("Please choose house"); System.out.println("C - choose house number"); System.out.println("R - pick a random house"); System.out.print("Enter your choice = "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'c' || optionChoiceA == 'C'){ System.out.print("Enter house number you want (1/2)= "); houseNumber = keyboard.nextInt(); if ((houseNumber >= 1) && (houseNumber <= 2)) { if(FloorA2[houseNumber-1] == 0 ) { FloorA2[houseNumber-1] += 1; System.out.println("Enter room number you want(1/2)= "); roomNumber = keyboard.nextInt(); if ((roomNumber >= 1) && (roomNumber <= 2)) { if (HouseA2[roomNumber-1] == 0 ) { HouseA2 [roomNumber-1] += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } else { next1 = false; System.out.println(); System.out.println("Sorry, this room is already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFullA = keyboard.nextLine(); optionChoiceFullA = userChoiceFullA.charAt(0); if (optionChoiceFullA == 'm' || optionChoiceFullA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFullA == 'q' || optionChoiceFullA == 'Q'){ System.exit(0); } break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } } else { next = false; System.out.println(); System.out.println("Sorry, these rooms are already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFull = keyboard.nextLine(); optionChoiceFull = userChoiceFull.charAt(0); if (optionChoiceFull == 'm' || optionChoiceFull == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFull == 'q' || optionChoiceFull == 'Q'){ System.exit(0); } break; } } else if (optionChoiceA == 'r' || optionChoiceA == 'R') { for ( index1 = 0; index1 < 2 ; index1++ ) { if (FloorA1[index1] == 0 ) { FloorA1[index1] += 1; houseNumber = index1; houseNumber += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } } } else { System.out.println(); System.out.println("Invalid choice"); System.out.println("Back to Main Menu"); System.out.println(); next = false; break; } } } break; case 'B': apartmentB: for (index = 0; index <=apartmentB.length; index++) { if (index == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } break;} else if (FloorB1[index] < 1){ System.out.println("What floor do you want? (1/2)"); userInput3 = keyboard.nextLine(); optionInput3 = userInput3.charAt(0); switch(optionInput3) { case '1': apartmentType = "Apartment Type B"; for (index2 = 0; index2 <=FloorB1.length; index2++) { if (index2 == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } else if (FloorB1[index2] < 1){ System.out.println("Please choose house"); System.out.println("C - choose house number"); System.out.println("R - pick a random house"); System.out.print("Enter your choice = "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'c' || optionChoiceA == 'C'){ System.out.print("Enter house number you want (1/2)= "); houseNumber = keyboard.nextInt(); if ((houseNumber >= 1) && (houseNumber <= 2)) { if(FloorB1[houseNumber-1] == 0 ) { FloorB1[houseNumber-1] += 1; System.out.println("Enter room number you want(1-2)= "); roomNumber = keyboard.nextInt(); if ((roomNumber >= 1) && (roomNumber <= 2)) { if (HouseB1[roomNumber-1] == 0 ) { HouseB1 [roomNumber-1] += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } else { next1 = false; System.out.println(); System.out.println("Sorry, this room is already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFullA = keyboard.nextLine(); optionChoiceFullA = userChoiceFullA.charAt(0); if (optionChoiceFullA == 'm' || optionChoiceFullA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFullA == 'q' || optionChoiceFullA == 'Q'){ System.exit(0); } break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } } else { next = false; System.out.println(); System.out.println("Sorry, these rooms are already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFull = keyboard.nextLine(); optionChoiceFull = userChoiceFull.charAt(0); if (optionChoiceFull == 'm' || optionChoiceFull == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFull == 'q' || optionChoiceFull == 'Q'){ System.exit(0); } break; } } else if (optionChoiceA == 'r' || optionChoiceA == 'R') { for ( index2 = 0; index2 < 2 ; index2++ ) { if (FloorA1[index2] == 0 ) { FloorA1[index2] += 1; houseNumber = index2; houseNumber += 1; next = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } } } else { System.out.println(); System.out.println("Invalid choice"); System.out.println("Back to Main Menu"); System.out.println(); next = false; break; } } } break; case '2': apartmentType = "Apartment Type B"; for (index2 = 0; index2 <=FloorB2.length; index2++) { if (index2 == 2) { System.out.println("Sorry, all houses are full."); System.out.println("Please look for another floor"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'm' || optionChoiceA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceA == 'q' || optionChoiceA == 'Q'){ System.exit(0); } else if (FloorB2[index2] < 1){ System.out.println("Please choose house"); System.out.println("C - choose house number"); System.out.println("R - pick a random house"); System.out.print("Enter your choice = "); userChoiceA = keyboard.nextLine(); optionChoiceA = userChoiceA.charAt(0); if (optionChoiceA == 'c' || optionChoiceA == 'C'){ System.out.print("Enter house number you want (1/2)= "); houseNumber = keyboard.nextInt(); if ((houseNumber >= 1) && (houseNumber <= 2)) { if(FloorB2[houseNumber-1] == 0 ) { FloorB2[houseNumber-1] += 1; System.out.println("Enter room number you want(1/2)= "); roomNumber = keyboard.nextInt(); if ((roomNumber >= 1) && (roomNumber <= 2)) { if (HouseB2[roomNumber-1] == 0 ) { HouseB2 [roomNumber-1] += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } else { next1 = false; System.out.println(); System.out.println("Sorry, this room is already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFullA = keyboard.nextLine(); optionChoiceFullA = userChoiceFullA.charAt(0); if (optionChoiceFullA == 'm' || optionChoiceFullA == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFullA == 'q' || optionChoiceFullA == 'Q'){ System.exit(0); } break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } else { System.out.println(); System.out.println("Wrong Type, Back to Main Menu"); next = false; break; } } } else { next = false; System.out.println(); System.out.println("Sorry, these rooms are already booked"); System.out.println("Please look for another room"); System.out.println(" M - Back to Main Menu"); System.out.println(" Q - Quit "); userChoiceFull = keyboard.nextLine(); optionChoiceFull = userChoiceFull.charAt(0); if (optionChoiceFull == 'm' || optionChoiceFull == 'M'){ System.out.println(); System.out.println("Main Menu."); } else if (optionChoiceFull == 'q' || optionChoiceFull == 'Q'){ System.exit(0); } break; } } else if (optionChoiceA == 'r' || optionChoiceA == 'R') { for ( index2 = 0; index2 < 2 ; index2++ ) { if (FloorA1[index2] == 0 ) { FloorA1[index2] += 1; houseNumber = index2; houseNumber += 1; next1 = true; DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date current = new Date(); DateFormat time = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.ENGLISH); currentHour = time.format( current ); Calendar today = Calendar.getInstance(); currentDate = sdf.format(today.getTime()); today.add(Calendar.DATE,140); assignDate = sdf.format(today.getTime()); System.out.println("Thanks, your room is in room "+ roomNumber +", house number"+ houseNumber +", 1st floor on "+ apartmentType); break; } } } else { System.out.println(); System.out.println("Invalid choice"); System.out.println("Back to Main Menu"); System.out.println(); next = false; break; } } } break; case 'v' : case 'V': System.out.println(" VIEW ROOM OCCUPANCY "); System.out.println("---------------------------------"); System.out.println("A - for Apartment A"); System.out.println("B - for Apartment B"); System.out.println("M - to return to Main Menu"); System.out.print("Enter : "); userInput1 = keyboard.nextLine(); optionInput1 = userInput1.charAt(0); if(optionInput1 == 'M' || optionInput1 == 'm') { System.out.println(); System.out.println("Back to Main Menu."); System.out.println(); } else if(optionInput1 == 'A' || optionInput1 == 'a') { System.out.print("Please choose a floor number: (1-10)"); inputView1 = keyboard.nextLine(); choiceView1 = inputView1.charAt(0); switch (choiceView1){ case '1' : ID = 1; System.out.println("*************************************************"); System.out.println("* Apartment Type A *"); System.out.println("*************************************************"); System.out.print("*"); for(index1 = 0; index1 < FloorA1.length; index1++){ System.out.print(" " + FloorA1[index1]); if(index1 == 2){ System.out.print(" *"); System.out.println(); System.out.println("*************************************************"); System.out.print("*"); } } System.out.print(" *"); System.out.println(); System.out.println("*************************************************"); System.out.println("* Apartment Type B *"); System.out.println("*************************************************"); System.out.print("*"); for(index2 = 1; index2 < (FloorB1.length + 1); index2++){ System.out.print(" " + FloorB2[(index2-1)]); if(index2 % 5 == 0){ System.out.print(" *"); System.out.println(); System.out.println("*************************************************"); if(index2 / 5 == 0){ System.out.print("*"); } } } System.out.println(); break; } break; } case 'q' : case 'Q' : System.out.println("You quit the system"); System.exit(0); break; default : System.out.println("Wrong type, back to Main Menu."); break; } while( optionMain != 'q' || optionMain != 'Q'); } } } } } } } } } }