How can I insert objects into an array? Here I have a class called HotelRoom which contains getter, setter, and the constructor method.
public class HotelRoom {
int roomNumber;
String roomGuest;
public HotelRoom (int room, String guest) {
roomNumber = room;
roomGuest = guest;
}
public int getRoom() {
return roomNumber;
}
public void setRoom() {
roomNumber = room;
}
public String getName() {
return roomGuest;
}
public void setName() {
roomGuest = guest;
}
And here I have the main method containing the array initializer and the objects. I've also inserted the objects into the array however, when compiling, the problem arises in the print command and it states: "cannot find symbol - variable HotelRoom". What am I doing wrong?
public class Hotel {
public static void main (String [] args) {
HotelRoom[] rooms = new HotelRoom [5];
HotelRoom guest1 = new HotelRoom(67, "Harry");
HotelRoom guest2 = new HotelRoom(98, "Bob");
HotelRoom guest3 = new HotelRoom(34, "Steven");
HotelRoom guest4 = new HotelRoom(99, "Larry");
HotelRoom guest5 = new HotelRoom(103, "Patrick");
rooms[0] = guest1;
rooms[1] = guest2;
rooms[2] = guest3;
rooms[3] = guest4;
rooms[4] = guest5;
System.out.println (HotelRoom);
}
}
roomsinstead.