/** * Create a booking for a regular passenger with no seat specified. * * @param p the passenger for whom a booking is to be made * @precond p != null && !p.hasBookingOn(this) && remainingCapacity() > 0 */ public void makeBooking(Passenger p) { if (p == null) throw new RuntimeException("Cannot book a flight for a null passenger."); if (p.hasBookingOn(this)) throw new RuntimeException("Cannot book a Person twice on a Flight."); if (remainingCapacity() <= 0) throw new RuntimeException("Cannot make a booking on a full flight."); Booking b = new Booking(p, this); waitingSeatList.addLast(b); p.addBooking(b); numberBooked = numberBooked + 1; }
/** * Book a seat for a first-class passenger. * * @param p the passenger for whom a booking is to be made * @param seat the seat for the passenger * @param meal the meal plan for the passenger * @precond p != null && !p.hasBookingOn(this) && isSeatAvailable(seat) */ public void makeFirstClassBooking(Passenger p, String seat, String meal) { if (p == null) throw new RuntimeException("Cannot book a flight for a null passenger."); if (p.hasBookingOn(this)) throw new RuntimeException("Cannot book a Person twice on a Flight."); if (!isSeatAvailable(seat)) throw new RuntimeException( "Seat " + seat + " is invalid or already occupied " + "so cannot book it."); Booking b = new FirstClassBooking(p, this, seat, meal); setSeat(b); p.addBooking(b); numberBooked = numberBooked + 1; }