I\'m trying to develop an online hotel booking system. I have the main class which takes input from the user such as their name, their payment information, and other data field
Let makeReservation return the created Reservation object:
public Reservation makeReservation(int checkIn, int checkOut)//Other parameters
{
reservation = new Reservation(checkIn, checkOut);
return reservation;
}
(You could also create a getter for reservation
)
Then change your addReservation like this:
public void addReservation(Reservation res)
{
reservations.add(res);
}
And then just add it like this:
HotelReservationSystem hrs = new HotelReservationSystem();
Reservation res = hrs.makeReservation();
Room room = new Room();
room.addReservation(res);
However, you might want to rethink your model. Right now your HotelReservationSystem
is creating a reservation and only saves that one, overwriting old ones. What happens if you create more than one? Also how can you get the reservations for a certain room given the HotelReservationSystem object? Just some things to think about...