Java Days & Bookings
Posted
by
sys_debug
on Stack Overflow
See other posts from Stack Overflow
or by sys_debug
Published on 2011-11-16T17:36:23Z
Indexed on
2011/11/16
17:51 UTC
Read the original article
Hit count: 198
Ok this is an extension of a question I asked about earlier yet this is the next step that is unclear to me. Everything else will be ready and this part is driving me mad! some members provided great help and I already made progress with that info, but this is just another obstacle.
I am creating a booking object (as was suggested) that will have a start date and end date. each booking will also have a number of seats associated with it (that I require to reserve). The total available number of seats any given day 46 (as the total capacity of the hall is 46 seats).
so in assumption that I have a booking to be made in the system, and start date is 1st jan and end date is 10th jan. The question is how can I check the remaining seats in all those days between the range to see if requested number could be hosted or not? and then when the second booking is made, it will have to see that the days in this range already have less than 46 and decrement further if possible to host the reservation.
one of the members, and I appreciate his effort, gladly contributed a method to compare if this booking is after or before the existing bookings. The code provided is here:
public boolean overlapsWithExisting(Booking booking) {
final Date early = booking.getStart();
final Date late = booking.getEnd();
for(Booking existing : existingBookings) {
if(!(early.isAfter(existing.getEnd() || late.isBefore(existing.getStart()))
return true;
}
return false;
}
I just want to know how to associate 46 with each day and keep record of days that are decremented by bookings.
Thanks and reallllllly appreciated :D
© Stack Overflow or respective owner