Reputation: 4322
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)
Upvotes: 1
Views: 210
Reputation: 51030
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
Upvotes: 2