Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help! have no idea what's wrong with my code..

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help! have no idea what's wrong with my code..

    I got this error :

    at java.lang.String.charAt(String.java:658)
    at University_Apartment.main(University_Apartment.jav a:54)
    Java Result: 1

    when I choose the house number in my program..
    anybody know what's wrong with the code?
    Thank b4


    import java.text.*;
    import java.util.*;
     
    public class University_Apartment
    {
        public static void main (String[]arguments)
        {
            String studentName, studentID, passportNumber, currentDate, assignDate, currentHour, apartmentType1, apartmentType2;
            String userInputMain, userInputI, userInputR, userInputView;
            String userChoiceFullA, userChoiceFullB;
     
            char optionMain, optionInputI,optionInputR, optionInputView;
            char optionChoiceFullA, optionChoiceFullB;
     
            int indexHouseA,indexHouseB;
            int houseNumber, roomNumber;
     
    	final int roomA = 2;
    	final int roomB = 3;
            boolean next = false;
            boolean nextA = false;
            boolean nextB = false;
     
    	int[] HouseA1 = new int[roomA];
    	int[] HouseA2 = new int[roomA];
            int[] HouseA3 = new int[roomA];
            int[] HouseA4 = new int[roomA];
            int[] HouseA5 = new int[roomA];
    	int[] HouseB1 = new int[roomB];
    	int[] HouseB2 = new int[roomB];
            int[] HouseB3 = new int[roomB];
            int[] HouseB4 = new int[roomB];
            int[] HouseB5 = new int[roomB];
     
            Scanner keyboard = new Scanner (System.in);
     
            do {
            System.out.println();
            System.out.println("************************************");
    	System.out.println("****** Fortes Fortuna Apartment ****");
            System.out.println("*==================================*");
    	System.out.println("*            MAIN MENU             *");
    	System.out.println("*==================================*");
            System.out.println("*      I => Apartment Info         *");
    	System.out.println("*      R => Register New Student   *");
    	System.out.println("*      V => View Occupancy         *");
            System.out.println("*      S => Search Student         *");
    	System.out.println("*      Q => Quit                   *");
            System.out.println("*                                  *");
            System.out.println("*==================================*");
            System.out.println();
            System.out.print  ("Enter : ");
            userInputMain = keyboard.nextLine();
    	optionMain = userInputMain.charAt(0);
     
    	switch(optionMain)
    	{
                  case 'i' : case 'I':
                       System.out.println();
                       System.out.println("#=======================================#");
                       System.out.println("#         APARTMENT INFORMATION         #");
                       System.out.println("#=======================================#");
                       System.out.println("#                                       #");
                       System.out.println("#        A => Info Apartment A          #");
                       System.out.println("#        B => Info Apartment B          #");
                       System.out.println("#        M => return to Main Menu       #");
                       System.out.println("#                                       #");
                       System.out.println("#=======================================#");
                       System.out.print  ("Enter : ");
                       userInputI = keyboard.nextLine();
                       optionInputI = userInputI.charAt(0);
     
                            if(optionInputI == 'm' || optionInputI == 'M') {
                                System.out.println();
                                System.out.println("Back to Main Menu.");
                                System.out.println();
                                }
                            else if(optionInputI == 'a' || optionInputI == 'A') {
                                System.out.println();
                                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::");
                                System.out.println("::::            Apartment Type A               ::::");
                                System.out.println("::===============================================::");
                                System.out.println("::              * 2 bedrooms                     ::");
                                System.out.println(":: * Equipped with kitchen & laundry facilities  ::");
                                System.out.println("::         * Monthly rental = RM300.             ::");
                                System.out.println("::                                               ::");
                                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::");
                                }
                            else if (optionInputI == 'b' || optionInputI == 'B') {
                                System.out.println();
                                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::");
                                System.out.println("::::               Apartment Type B            ::::");
                                System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::");
                                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("___________________________________________________");
                                System.out.println("  * Master bedroom attached with inside bathroom   ");
                                System.out.println(" ** People who live in master bedroom              ");
                                System.out.println("                  will be paying 40% more = RM280  ");
                                System.out.println("___________________________________________________");
                                System.out.println();
                                }
     
                            break;
     
     
     
     
                  case 'r': case 'R':
     
                        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();
                        System.out.println("    Register New Student");
                        System.out.println("---------------------------------");
                        System.out.println("Enter your name : ");
                        studentName = keyboard.nextLine();
                        System.out.println();
     
                        System.out.println("Enter your Full Student ID (ex: TP123456): ");
                        studentID = keyboard.nextLine();
                        System.out.println();
     
     
                        System.out.println("Enter your Full Passport Number(include the Letter): ");
                        passportNumber = keyboard.nextLine();
                        System.out.println();
     
     
                        System.out.println("Which apartment type you want? (A/B)");
                        userInputI = keyboard.nextLine();
                        optionInputI = userInputI.charAt(0);
                        System.out.println();
     
                        if(optionInputI == 'a' || optionInputI == 'A') {
                            apartmentType1 = "Apartment Type A";
     
                                    System.out.println("Which house do you want?");
                                    System.out.println("#.  House");
                                    System.out.println("1     A1 ");
                                    System.out.println("2     A2 ");
                                    System.out.println("3     A3 ");
                                    System.out.println("4     A4 ");
                                    System.out.println("5     A5 ");
     
    				houseNumber = keyboard.nextInt();
     
                                    switch(houseNumber) {
     
                                    case '1' :
     
     
                                        for (indexHouseA = 0; indexHouseA <=HouseA1.length; indexHouseA++) {
    					if (indexHouseA == 2) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseA1[indexHouseA] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2)");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseA1[roomNumber-1] == 0 ) {
                                                    HouseA1 [roomNumber-1] += 1;
                                                    nextA = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType1+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextA = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '2' :
     
                                        for (indexHouseA = 0; indexHouseA <=HouseA2.length; indexHouseA++) {
    					if (indexHouseA == 2) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseA2[indexHouseA] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2)");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseA2[roomNumber-1] == 0 ) {
                                                    HouseA2 [roomNumber-1] += 1;
                                                    nextA = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType1+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextA = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '3':
     
                                        for (indexHouseA = 0; indexHouseA <=HouseA3.length; indexHouseA++) {
    					if (indexHouseA == 2) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseA3[indexHouseA] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2)");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseA3[roomNumber-1] == 0 ) {
                                                    HouseA3 [roomNumber-1] += 1;
                                                    nextA = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType1+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextA = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '4':
     
                                        for (indexHouseA = 0; indexHouseA <=HouseA4.length; indexHouseA++) {
    					if (indexHouseA == 2) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseA4[indexHouseA] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2)");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseA4[roomNumber-1] == 0 ) {
                                                    HouseA4 [roomNumber-1] += 1;
                                                    nextA = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType1+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextA = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '5':
     
                                        for (indexHouseA = 0; indexHouseA <=HouseA5.length; indexHouseA++) {
    					if (indexHouseA == 2) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseA5[indexHouseA] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2)");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseA5[roomNumber-1] == 0 ) {
                                                    HouseA5 [roomNumber-1] += 1;
                                                    nextA = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType1+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextA = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    }break;
                        }
                        else if(optionInputI == 'b' || optionInputI == 'B') {
                            apartmentType2 = "Apartment Type B";
     
                            System.out.println("Which house do you want?");
                                    System.out.println("#.  House");
                                    System.out.println("1     B1 ");
                                    System.out.println("2     B2 ");
                                    System.out.println("3     B3 ");
                                    System.out.println("4     B4 ");
                                    System.out.println("5     B5 ");
     
    				houseNumber = keyboard.nextInt();
     
                                    switch(houseNumber) {
     
                                    case '1' :
     
     
                                        for (indexHouseB = 0; indexHouseB <=HouseB1.length; indexHouseB++) {
    					if (indexHouseB == 3) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseB1[indexHouseB] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2/3)");
                                                System.out.println(" *note = 3 is Master Bedroom");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseB1[roomNumber-1] == 0 ) {
                                                    HouseB1 [roomNumber-1] += 1;
                                                    nextB = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType2+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextB = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '2' :
     
     
                                        for (indexHouseB = 0; indexHouseB <=HouseB2.length; indexHouseB++) {
    					if (indexHouseB == 3) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseB2[indexHouseB] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2/3)");
                                                System.out.println(" *note = 3 is Master Bedroom");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseB2[roomNumber-1] == 0 ) {
                                                    HouseB2 [roomNumber-1] += 1;
                                                    nextB = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType2+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextB = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '3' :
     
     
                                        for (indexHouseB = 0; indexHouseB <=HouseB3.length; indexHouseB++) {
    					if (indexHouseB == 3) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseB3[indexHouseB] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2/3)");
                                                System.out.println(" *note = 3 is Master Bedroom");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseB3[roomNumber-1] == 0 ) {
                                                    HouseB3 [roomNumber-1] += 1;
                                                    nextB = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType2+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextB = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '4' :
     
     
                                        for (indexHouseB = 0; indexHouseB <=HouseB4.length; indexHouseB++) {
    					if (indexHouseB == 3) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseB4[indexHouseB] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2/3)");
                                                System.out.println(" *note = 3 is Master Bedroom");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseB4[roomNumber-1] == 0 ) {
                                                    HouseB4 [roomNumber-1] += 1;
                                                    nextB = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType2+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextB = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    case '5' :
     
     
                                        for (indexHouseB = 0; indexHouseB <=HouseB5.length; indexHouseB++) {
    					if (indexHouseB == 3) {
    						System.out.println();
                                                    System.out.println("Sorry, this house is full.");
                                                    System.out.println("Please look for another house");
                                                    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 if (HouseB5[indexHouseB] < 1){
                                                System.out.println();
                                                System.out.println("Which room do you want? (1/2/3)");
                                                System.out.println(" *note = 3 is Master Bedroom");
                                                roomNumber = keyboard.nextInt();
     
                                                if (roomNumber == 1){
                                                    if (HouseB5[roomNumber-1] == 0 ) {
                                                    HouseB5 [roomNumber-1] += 1;
                                                    nextB = true;
     
                                                    System.out.println("Thanks, your room is in room number "+roomNumber+", house "+houseNumber+" "+
                                                                       "on "+apartmentType2+".");
                                                    System.out.println("Please pay all the administration fees.");
                                                    System.out.println("You will be assigned till "+ assignDate +".");
                                                    }
                                                }
     
                                                else {
                                                nextB = false;
                                                System.out.println();
                                                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;
                                                }break;
                                        }break;
     
                                    }break;
                        }
     
                        else {
                        next = false;
                        System.out.println();
                        System.out.println("Wrong type, Back to Main Menu");
                        System.out.println();
                        }break;
     
     
     
                    case 'v' : case 'V':     
                            System.out.println();
                            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 : ");
                            userInputI = keyboard.nextLine();
                            optionInputI = userInputI.charAt(0);
                                if(optionInputI == 'M' || optionInputI == 'm') {
    				System.out.println();
    				System.out.println("Back to Main Menu.");
    				System.out.println();
                                }
                                else if(optionInputI == 'A' || optionInputI == 'a') {
                                    System.out.println();
    				System.out.print("Please choose a house number: (1 - 5)");
                                    userInputView = keyboard.nextLine();
                                    optionInputView = userInputView.charAt(0);
     
                                    switch (optionInputView){
                                        case '1' :
     
                                                System.out.println();
                                                System.out.println("************************************");
                                                System.out.println("*        Apartment A (House 1)      *");
                                                System.out.println("************************************");
                                                System.out.print("*");
     
                                                for(indexHouseA = 0; indexHouseA < HouseA1.length; indexHouseA++){
                                                    System.out.print("       " + HouseA1[indexHouseA]);
     
                                                    if(indexHouseA == 2){
                                                        System.out.print("                                             ");
                                                        System.out.println();
                                                        System.out.println("********************************************");
                                                        if(indexHouseA == 2){
                                                        System.out.println();
     
     
     
                                                    }
                                                    }
                                                }System.out.println();
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                        case '2' :
     
                                                System.out.println();
                                                System.out.println("************************************");
                                                System.out.println("*        Apartment A (House 2)      *");
                                                System.out.println("************************************");
                                                System.out.print("*");
                                                for(indexHouseA = 0; indexHouseA < HouseA2.length; indexHouseA++){
                                                    System.out.print("       " + HouseA2[indexHouseA]);
                                                    if(indexHouseA == 2){
                                                        System.out.print("                                             ");
                                                        System.out.println();
                                                        System.out.println("********************************************");
                                                        if(indexHouseA == 2){
                                                        System.out.println();
     
                                                    }
                                                    }
                                                }System.out.println();
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
     
                                        case '3' :
     
                                                System.out.println();
                                                System.out.println("************************************");
                                                System.out.println("*        Apartment A (House 3)      *");
                                                System.out.println("************************************");
                                                System.out.print("*");
                                                for(indexHouseA = 0; indexHouseA < HouseA3.length; indexHouseA++){
                                                    System.out.print("       " + HouseA3[indexHouseA]);
                                                    if(indexHouseA == 2){
                                                        System.out.print("                                             ");
                                                        System.out.println();
                                                        System.out.println("********************************************");
                                                        if(indexHouseA == 2){
                                                        System.out.println();
     
                                                    }
                                                    }
                                                }System.out.println();
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                        case '4' :
     
                                                System.out.println();
                                                System.out.println("************************************");
                                                System.out.println("*        Apartment A (House 4)      *");
                                                System.out.println("************************************");
                                                System.out.print("*");
                                                for(indexHouseA = 0; indexHouseA < HouseA4.length; indexHouseA++){
                                                    System.out.print("       " + HouseA4[indexHouseA]);
                                                    if(indexHouseA == 2){
                                                        System.out.print("                                             ");
                                                        System.out.println();
                                                        System.out.println("********************************************");
                                                        if(indexHouseA == 2){
                                                        System.out.println();
     
                                                    }
                                                    }
                                                }System.out.println();
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                        case '5' :
     
                                                System.out.println();
                                                System.out.println("************************************");
                                                System.out.println("*        Apartment A (House 5)      *");
                                                System.out.println("************************************");
                                                System.out.print("*");
                                                for(indexHouseA = 0; indexHouseA < HouseA5.length; indexHouseA++){
                                                    System.out.print("       " + HouseA5[indexHouseA]);
                                                    if(indexHouseA == 2){
                                                        System.out.print("                                             ");
                                                        System.out.println();
                                                        System.out.println("********************************************");
                                                        if(indexHouseA == 2){
                                                        System.out.println();
     
                                                    }
                                                    }
                                                }System.out.println();
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;    
     
                                    }break;
                                }
     
                                else if(optionInputI == 'b' || optionInputI == 'B') {
                                    System.out.println();
    				System.out.print("Please choose a house number: (1 - 5)");
                                    userInputView = keyboard.nextLine();
                                    optionInputView = userInputView.charAt(0);
     
                                    switch (optionInputView){
                                        case '1' :
     
                                                System.out.println();
                                                System.out.println("*************************************");
                                                System.out.println("*          Apartment B (House 1)    *");
                                                System.out.println("*************************************");
                                                System.out.print("*");
                                                for(indexHouseB = 0; indexHouseB < HouseB1.length; indexHouseB++){
                                                    System.out.print("       " + HouseB1[indexHouseB]);
                                                    if(indexHouseB == 3){
                                                        System.out.print("                                          *");
                                                        System.out.println();
                                                        System.out.println("*****************************************");
                                                        System.out.println();
     
                                                    }
     
     
                                                }System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                        case '2' :
     
                                                System.out.println();
                                                System.out.println("*************************************");
                                                System.out.println("*          Apartment B (House 2)    *");
                                                System.out.println("*************************************");
                                                System.out.print("*");
                                                for(indexHouseB = 0; indexHouseB < HouseB2.length; indexHouseB++){
                                                    System.out.print("       " + HouseB2[indexHouseB]);
                                                    if(indexHouseB == 3){
                                                        System.out.print("                                          *");
                                                        System.out.println();
                                                        System.out.println("*****************************************");
                                                        System.out.println();
     
                                                    }
     
     
                                                }
                                                System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                        case '3' :
     
                                                System.out.println();
                                                System.out.println("*************************************");
                                                System.out.println("*          Apartment B (House 3)    *");
                                                System.out.println("*************************************");
                                                System.out.print("*");
                                                for(indexHouseB = 0; indexHouseB < HouseB3.length; indexHouseB++){
                                                    System.out.print("       " + HouseB3[indexHouseB]);
                                                    if(indexHouseB == 3){
                                                        System.out.print("                                          *");
                                                        System.out.println();
                                                        System.out.println("*****************************************");
                                                        System.out.println();
     
                                                    }
     
     
                                                }System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                         case '4' :
     
                                                System.out.println();
                                                System.out.println("*************************************");
                                                System.out.println("*          Apartment B (House 4)    *");
                                                System.out.println("*************************************");
                                                System.out.print("*");
                                                for(indexHouseB = 0; indexHouseB < HouseB4.length; indexHouseB++){
                                                    System.out.print("       " + HouseB4[indexHouseB]);
                                                    if(indexHouseB == 3){
                                                        System.out.print("                                          *");
                                                        System.out.println();
                                                        System.out.println("*****************************************");
                                                        System.out.println();
     
                                                    }
     
     
                                                }System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
     
                                         case '5' :
     
                                                System.out.println();
                                                System.out.println("*************************************");
                                                System.out.println("*          Apartment B (House 5)    *");
                                                System.out.println("*************************************");
                                                System.out.print("*");
                                                for(indexHouseB = 0; indexHouseB < HouseB5.length; indexHouseB++){
                                                    System.out.print("       " + HouseB5[indexHouseB]);
                                                    if(indexHouseB == 3){
                                                        System.out.print("                                          *");
                                                        System.out.println();
                                                        System.out.println("*****************************************");
                                                        System.out.println();
     
                                                    }
     
     
                                                }System.out.println();
                                                System.out.println("HINT :       ");
                                                System.out.println("[ 0 => available ]");
                                                System.out.println("[ 1 => reserved  ]");
                                                break;
                                    }break;
                                }
     
                                else {
                                next = false;
                                System.out.println();
                                System.out.println("Wrong type, Back to Main Menu");
                                System.out.println();
                                }break;
     
     
                   case 's' : case 'S' :
                        System.out.println();
                        System.out.println("Insert Full Student ID number (ex: TP123456");
                        System.out.println();
     
     
     
     
     
                   case 'q' : case 'Q' :
                        System.out.println();
                        System.out.println("You quit the system");
                        System.exit(0);
                        break;
     
     
                   default :
                        System.out.println();
                        System.out.println("Wrong type, back to Main Menu.");
                        break;
     
                }       
     
     
            }while( optionMain != 'q' || optionMain != 'Q');
            }
    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help! have no idea what's wrong with my code..

    You need to show the whole error message, not a little blip of it. As it is, your error message is missing important parts.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! have no idea what's wrong with my code..

    i run it on NetBean, and this the error:

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:658)
    at University_Apartment.main(University_Apartment.jav a:54)
    Java Result: 1

    what should i do?

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help! have no idea what's wrong with my code..

    So which line of your code does the error refer to (line 54 of University_Apartment)? You seem to be working with an empty String there, "", and are treating it as if it were non-empty.

Similar Threads

  1. Please HELP! my code is wrong somewhere.
    By mcpanthers22 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: September 19th, 2012, 01:12 PM
  2. How do I expand this code? I have no idea what my teacher wants.
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 3rd, 2012, 10:18 PM
  3. Replies: 2
    Last Post: September 2nd, 2012, 02:06 PM
  4. what is wrong with my code? need help
    By balmung123 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 1st, 2012, 04:12 AM
  5. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 29th, 2012, 03:33 PM