1

I currently have a class Room and a class Hostel which holds rooms = new ArrayList < Room >();. I then have a BookRoomGUI class.

When a room is added to the arraylist it uses the following constructor:

public Room(int newRoomNo, boolean newRoomEnSuite)
{
    roomNo = newRoomNo;
    roomEnSuite = newRoomEnSuite;
    roomBooking = "Free";
    roomNights = 0;
    roomBooker = "No Booker";
}

In the BookRoomGUI class i have the following JTextFields:

    fields.add(roomnumberJTextField);
    fields.add(bookerJtextField);
    fields.add(nightsJTextField);
    fields.add(peoplenoJTextField);

I am trying to make a method within Hostel which will take the values of these text fields and alter the corresponding variables in the original constructor if the room number matches:

public int makeBooking(int number)
{
  for (Room room : rooms)
  {
     if (number == room.getRoomNo())
     {
         room.setRoomBooker(bookRoom.booker);
     }
  }
}

My question is what should go in the if statement? currently i use booker = bookerJtextField.getText(); to take the text from the text field in BookRoomGUI and setRoomBooker in Room but this does not work and i am presented with

setRoomBooker() in Room cannot be applied to (java.lang.String)

1
  • It would be better to store the rooms in a number -> Room map instead of list. Make sure you have setRoomBooker(String) method in Room class. Commented Dec 20, 2011 at 14:30

1 Answer 1

2

Make sure you have the following method in Room:

public void setRoomBooker(String roomBooker) {
    this.roomBooker = roomBooker;
}

Right now, if you look at the error messege:

setRoomBooker() in Room cannot be applied to (java.lang.String)

You can see that your setRoomBooker() method currently is not defined to take a parameter of type java.lang.String (or any parameter at all).

So, you need to change the definition of that method, for you to be able to do the following:

room.setRoomBooker(bookRoom.booker); //<-- You are passing it an argument of type String
Sign up to request clarification or add additional context in comments.

3 Comments

Would this mean i need to alter the getRoomNumber method also?
No. It has nothing do with getRoomNumber method. Are you sure that your Room class has the above method?
taken a step back and just attempted to modify the arraylist without the GUI to start, your fix worked though, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.