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
I believe you must have tried this
public void addReservation(Reservation reservation)
{
reservations.add(reservation);
}
but the problem here is that your list reservations
is null and will throw null pointer exception. So better initialize it at declaration. So change this
private ArrayList reservations;
to
private ArrayList reservations = new ArrayList();
And in your makeReservation
method of Hotel
class do this:
Room room = new Room();
room.addReservation(reservation);