Skip to content

Commit

Permalink
Ticket booking system logic added
Browse files Browse the repository at this point in the history
  • Loading branch information
4Vitalii5 committed Dec 6, 2024
1 parent 8845009 commit 90bcef6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/mate/academy/TicketBookingSystem.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package mate.academy;

import java.util.concurrent.Semaphore;

public class TicketBookingSystem {
private final Semaphore seats;

public TicketBookingSystem(int totalSeats) {

this.seats = new Semaphore(totalSeats);
}

public BookingResult attemptBooking(String user) {
return null;
if (seats.tryAcquire()) {
return new BookingResult(user, true, "Booking successful.");
} else {
return new BookingResult(user, false, "No seats available.");
}
}
}

0 comments on commit 90bcef6

Please sign in to comment.