0

I am now recieveing this error. I updated evrything.
** choice=scan.nextchar(); ** that bit code just always comes up red

MENU 
A) Add Guest
V) View All Rooms
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.util.Scanner.nextchar
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
    at hotelprogram.Hotelprogram.main(Hotelprogram.java:33)
R) View Rooms Alphabetically
E) Exit program
Choice: Choice: Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
0
String names[]=new String[0];
        int rooms[]=new int[0]; 

The code above says the variable is not in use do i need to move this somewhere? I have used the variables in the method coding

0

sorry about that nextChar method does not exist
do it like you were doing earlier:

char choice = (char)scan.nextLine().charAt(0);

Edited by DarkLightning7

0

How come the variables are not in use..

Also the word choice does it have to have a capitcal C through out?

MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: Choice: A
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable choice might not have been initialized
    at hotelprogram.Hotelprogram.main(Hotelprogram.java:34)
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
0

variables are cases sensitive meaning they have to match exactly for java to think they are the same thing.

Standard is to make variables camelCase first word lowercase and all following words uppercase

example: thisIsCamelCase

0

I have fixed that one but most of my code is all red underlined.. :(

MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: Choice: A
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: addGuest
    at hotelprogram.Hotelprogram.main(Hotelprogram.java:42)
Java Result: 1
0

well for starters whats on line 42?

also check what netbeans tells you by hovering your mouse over the caution symbols on the left of your code.

0

**line 42 has addGuest();
**

  char Choice = (char)scan.nextLine().charAt(0);                        
                        if(Choice=='E')          //if the selection is E exit the loop

                              break;

                                  switch(Choice)
                                          {

                                      case 'A':
                                addGuest();
                                break;
                               case 'V':
                               viewRooms();
                                break;
                               default:
                                   break;
                                  }}}}

                              public void addGuest(){
                        //Add Guest
                        scan.nextLine();
                        System.out.print("Please enter your guest: ");
                        String guest=scan.nextLine();
                        names=addName(guest,names);
                        System.out.print("Room: ");
                        int room=scan.nextInt();
                        rooms=addRoom(room,rooms);
                        //sort rooms by ascending... don't use arrays.sort!
                        for(int x=0;x<rooms.length;x++)
                        {
                            for(int y=0;y<rooms.length;y++)
                            {
                                if(rooms[x]<rooms[y])
                                {
                                    int dummy=rooms[x];
                                    String dummy2=names[x];
                                    rooms[x]=rooms[y];
                                    names[x]=names[y];
                                    rooms[y]=dummy;
                                    names[y]=dummy2;
}}}




                     public void viewRooms(){
                    {
                        //List All Guests and Room Numbers
                        System.out.println("ROOM\t\t\tGUEST");
                        for(int x=0;x<rooms.length;x++)
                        {
                            System.out.println(rooms[x]+"\t\t\t"+ names[x]);
                        }

                                        }}

    public static String[] addName(String guest, String names[])
    {
        String x[]=new String[(names.length)+1];
        System.arraycopy(names,0,x,0,names.length);//System.arraycopy(first array, starting point, second array, start point, how much
        //add something for maybe if the person is already here, but cased differently??
        for(int a=0;a<x.length;a++)
        {
            if(guest.equalsIgnoreCase(x[a]))
            {
                System.out.println("This guest has already checked in.");
                System.out.print("New Guest: ");
                guest=scan.nextLine();
            }
        }
        x[x.length-1]=guest;
        return x;   
    }

    public static int[] addRoom(int room, int rooms[])
    {
        int r[]=new int[(rooms.length)+1];
        System.arraycopy(rooms,0,r,0,rooms.length);//System.arraycopy(first array, starting point, second array, start point, how much
        for(int x=0;x<r.length;x++)
        {
            if(r[x]==room)
            {
                System.out.println("ROOM ALREADY OCCUPIED!");
                System.out.print("Reenter room: ");
                room=scan.nextInt();
            }
        }
        r[r.length-1]=room;
        return r;
}
0

i corrected all the problems i could find the program now works for the first two choices. the problems are listed in the comments the first time they show all proceeding instances are uncommented.

This is a great little program i hope you continue to improve your skills.

A couple things you should do before working on this any more:
1. read about scope in java
2. read about static vs non static

package tests;

import java.util.Scanner;

public class Test {
    static String names[]=new String[0]; 
    static int rooms[]=new int[0];      //had to move these outside of main to make them accessable to your methods.

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        do{
            char choice;
            System.out.println("\n\nMENU ");//menu
            System.out.println("A) Add Guest");
            System.out.println("V) View All Rooms");
            System.out.println("D) Display Empty Rooms");
            System.out.println("F) Find Room From Customer Name");
            System.out.println("S) Store Program data into file");
            System.out.println("L) Load Program from data file");
            System.out.println("R) View Rooms Alphabetically");
            System.out.println("E) Exit program");
            System.out.print("Choice: ");

            char Choice = (char)scan.nextLine().charAt(0);

            if(Choice=='E')
                break;

            switch(Choice){
                case 'A':
                    addGuest();  //you were calling a non static method from main here.  that not allowed
                    break;
                case 'V':
                    viewRooms();
                    break;
                default:
                    break;
             }

        }while(true);
    }

    public static void addGuest(){  //if you dont put methodds in a seperate class and instance an object they have to be static to use inside of main.
        Scanner scan = new Scanner(System.in);  //variable scope is importaint since the previous scanner is in main you need to create a new one inside of all of your methods that are outside of main.
        scan.nextLine();

        System.out.print("Please enter your guest: ");
        String guest=scan.nextLine();

        names=addName(guest,names);
        System.out.print("Room: ");

        int room=scan.nextInt();
        rooms=addRoom(room,rooms);
        //sort rooms by ascending... don't use arrays.sort!

        for(int x=0;x<rooms.length;x++){
            for(int y=0;y<rooms.length;y++){
                if(rooms[x]<rooms[y]){
                    int dummy=rooms[x];
                    String dummy2=names[x];
                    rooms[x]=rooms[y];
                    names[x]=names[y];
                    rooms[y]=dummy;
                    names[y]=dummy2;
                }
            }
        }
    }

    public static void viewRooms(){
        System.out.println("ROOM\t\t\tGUEST");
        for(int x=0;x<rooms.length;x++){
            System.out.println(rooms[x]+"\t\t\t"+ names[x]);
        }
    }

    public static String[] addName(String guest, String names[]){
        Scanner scan = new Scanner(System.in);
        String x[]=new String[(names.length)+1];
        System.arraycopy(names,0,x,0,names.length);

        for(int a=0;a<x.length;a++){
            if(guest.equalsIgnoreCase(x[a])){
                System.out.println("This guest has already checked in.");
                System.out.print("New Guest: ");
                guest=scan.nextLine();
            }
        }

        x[x.length-1]=guest;
        return x;   
    }

    public static int[] addRoom(int room, int rooms[]){
        Scanner scan = new Scanner(System.in);
        int r[]=new int[(rooms.length)+1];
        System.arraycopy(rooms,0,r,0,rooms.length);

        for(int x=0;x<r.length;x++){
            if(r[x]==room){
                System.out.println("ROOM ALREADY OCCUPIED!");
                System.out.print("Reenter room: ");
                room=scan.nextInt();
            }
        }

        r[r.length-1]=room;
        return r;
    }
}
0

i will start reading in to what u have suggested asap..

for now i still have a error.. when i take static out the error goes but doesnt run.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable names cannot be referenced from a static context
    at hotelprogram.Hotelprogram.addGuest(Hotelprogram.java:64)
    at hotelprogram.Hotelprogram.main(Hotelprogram.java:44)
Java Result: 1






                              public static void addGuest(){

                              Scanner scan = new Scanner(System.in);
                        //Add Guest
                        scan.nextLine();

      System.out.print("Please enter your guest: ");
        String guest=scan.nextLine();
        names=addName(guest,names);
        System.out.print("Room: ");
        int room=scan.nextInt();
        rooms=addRoom(room,rooms);
        //sort rooms by ascending... don't use arrays.sort!
        for(int x=0;x<rooms.length;x++){
            for(int y=0;y<rooms.length;y++){
                if(rooms[x]<rooms[y]){
                    int dummy=rooms[x];
                    String dummy2=names[x];
                    rooms[x]=rooms[y];
                    names[x]=names[y];
                    rooms[y]=dummy;
                    names[y]=dummy2;
                }
            }
        }
    }

Edited by uknown2: not complete

0

Are you sure you copied what I gave you exactly? i tested the program before posting it to make sure i found all the problems. It should work as is.

also the stack trace doesnt do any good if i dont know where line 44 and 64 are.

0

yea i did.. ill go throught it proper

Edited by uknown2: wrong post

0

I have got it working thank you..

I just need to work on the other methods. :)

I really appreciate the time u have take out to reply and helped me.

Thank You very much..

I may need some help with the methods like reading from file, storing data in file etc.. but ill work on it and then if i need help ill let u.

Thank you once again

0

I am trying to do the look up guest method but i have a slight problem..

if the guest hasnt checked in it gives ERROR..

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at hotel_program.Main.lookupCustomer(Main.java:91)
    at hotel_program.Main.main(Main.java:43)
Java Result: 1

LINE 91 IS

    System.out.println(names[search]+" has not checked into this hotel");

LINE 43 IS

 lookupCustomer();

it finds the customer to begin.
it works but it just doesnt do what its meants to..

please cn you tell me where i have gone wrong?

public static void lookupCustomer(){            
//Search for a cstomer
             Scanner scan = new Scanner(System.in);
scan.nextLine();
int search=-1;
System.out.print("Enter the name of the guest that is being searched: ");** //I CHANGED THIS SEMI-CLN TO A COLLON IT THEN ALLOWS THE DIFFERNT CUSTOMER SEARCH TO HAPPEN SHOWING DIFFERNT CUSTMERS RATHER THAN THE SAME NAME AGAIN AND AGAIN**
String searchName=scan.nextLine();
for(int x=0;x<names.length;x++)
{   
if(names[x].equalsIgnoreCase(searchName));
{//Every time I search for a guest it says the guest of the first cell is here will explain with output
    search=x;
    break;
}   }                   
if(search==-1)
System.out.println(names[search]+" has not checked into this hotel");
else
   System.out.println(names[search]+" is checked into room "+rooms[search]);

                    }

Edited by JamesCherrill: Poster's request - special case

0

The array index out of bounds error means that your trying to access part of the array that does not exist. so your index is either bigger than the last element in the array (array.length-1) or less than 0. see if you can find where your index is becomming larger than the number of values in the array.

0

I have been trying to research it but i cant seem to fix the error just keep coming up with more errors. :(
Do u know of any site that may help me understand??

0

if you notice in your previous post your allowing search to become negative then using it as an array index. Array indexes can't be negative. They start at 0 and go till the end of the array.

0

I have changed it but now the if else statment is not working accordingly. The search is not working properly..
the results are as follows.

MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: A

Please enter your guest: ALEX
Room: 1


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: A

Please enter your guest: RYAN
Room: 
2


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: V
ROOM            GUEST
1           ALEX
2           RYAN


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: F

Enter the name of the guest that is being searched: RYAN
ALEX is checked into room 1


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: F

Enter the name of the guest that is being searched: ALEX
ALEX is checked into room 1


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: E
BUILD SUCCESSFUL (total time: 51 seconds)

Edited by uknown2: update

0

here are two problems i noticed with your last code post. If they dont fix your problem go ahead and post your code again so i can look for the problem.

public static void lookupCustomer(){            
    Scanner scan = new Scanner(System.in);
    scan.nextLine();
    int search=-1;

    System.out.print("Enter the name of the guest that is being searched: ");
    String searchName=scan.nextLine();

    for(int x=0;x<names.length;x++){  //just a comment not shure if you know this or not its fine here.  If names last index is 19 names.length will return 20.  be careful.   
        if(names[x].equalsIgnoreCase(searchName));{  // there should not be a semi colin here this is your search problem.
            search=x;
            break;
        }
    }

    if(search==-1)  //checking if search == -1 is fine as long as you dont use it as an array index if it is -1
    System.out.println(names[search]+" has not checked into this hotel"); //this line names[search] should be replaced by searchName
    else
        System.out.println(names[search]+" is checked into room "+rooms[search]);
}

Edited by DarkLightning7

0

Hey sorry about the late reply...

I am still having an error.. the error is within these lines. i tried to change the code around but not successfull.

    if (search==-1)  //checking if search == -1 is fine as long as you dont use it as an array index if it is -1
    System.out.println(names[searchName]+" has not checked into this hotel"); //this line names[search] should be replaced by searchName
    else{
        System.out.println(names[searchName]+" is checked into room "+rooms[search]);
}}

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
required: int

0

*judging from recent posts

your array expects an integer and searchName is a String

Edited by zeroliken

-1

pLEASE CAN SOME ONE HELP ME FIX THIS CODE.. I JUST DONT UNDERSTAND WHY ITS NOT LOOKING UP THE CUSTOMER WITH THE CORRECT NAME BEING SEARCHED..
THE OUT PUT FOR THIS CODE IS .....

MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: A

Please enter your guest: TOM
Room: 4


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: A

Please enter your guest: PHIL
Room: 3


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: V
ROOM            GUEST
3           PHIL
4           TOM


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: F

Enter the name of the guest that is being searched: TOM
PHIL has not checked into this hotel


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: F

Enter the name of the guest that is being searched: PHIL
PHIL has not checked into this hotel







 public static void lookupCustomer(){            
    Scanner scan = new Scanner(System.in);
    scan.nextLine();
    int search=0;
    System.out.print("Enter the name of the guest that is being searched: ");
    String searchName=scan.nextLine();
    for(int x=0;x<names.length;x++){  //just a comment not shure if you know this or not its fine here.  If names last index is 19 names.length will return 20.  be careful.   
        if(names[x].equalsIgnoreCase(searchName));{  // there should not be a semi colin here this is your search problem.
            search=x;
            break;
0

please can any one help me. how would i change the code to get a string and not a int???

0

erm but with my code it wants a interger but i need to change it to an string..

how would i do that

public static void lookupCustomer(){            
    Scanner scan = new Scanner(System.in);
    scan.nextLine();
    int search=0;
    System.out.print("Enter the name of the guest that is being searched: ");
    String searchName=scan.nextLine();
    for(int x=0;x<names.length;x++){   
        if(names[x].equalsIgnoreCase(searchName));{  
            search=x;
            break;

Edited by uknown2: uopdate

0

THERE IS NO ERROR WITH THE CODE!! BUT THE OUT COMES OUT WRONG..

BELOW I HAVE ADDED 2 CUSTOMERS AND THEN PRESSED "F" TO FIND THE CUSTOMER BUT THE OUTPUT IS WRONG...
IF U LOOK AT THE LAST THRE MENU OUTPUTS U WILL SEE WHAT IM SAYING

MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: A

Please enter your guest: TOM
Room: 2




    MENU 
    A) Add Guest
    V) View All Rooms
    D) Display Empty Rooms
    F) Find Room From Customer Name
    S) Store Program data into file
    L) Load Program from data file
    R) View Rooms Alphabetically
    E) Exit program
    Choice: A

    Please enter your guest: LISA
    Room: 2
    ROOM ALREADY OCCUPIED!
    Reenter room: 4


    MENU 
    A) Add Guest
    V) View All Rooms
    D) Display Empty Rooms
    F) Find Room From Customer Name
    S) Store Program data into file
    L) Load Program from data file
    R) View Rooms Alphabetically
    E) Exit program
    Choice: F

    Enter the name of the guest that is being searched: LISA
    TOM is checked into room 2


    MENU 
    A) Add Guest
    V) View All Rooms
    D) Display Empty Rooms
    F) Find Room From Customer Name
    S) Store Program data into file
    L) Load Program from data file
    R) View Rooms Alphabetically
    E) Exit program
    Choice: F

    Enter the name of the guest that is being searched: TOM
    TOM is checked into room 2


MENU 
A) Add Guest
V) View All Rooms
D) Display Empty Rooms
F) Find Room From Customer Name
S) Store Program data into file
L) Load Program from data file
R) View Rooms Alphabetically
E) Exit program
Choice: F

Enter the name of the guest that is being searched: PHIL
TOM is checked into room 2

Edited by uknown2: UP

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.