public class SeatReservation {
  private final String[] seats;
  
  public SeatReservation(int capacity) {
    this.seats = new String[capacity];
  }
  
  public int tryToReserve(int seatCount, String symbol) {
    if (seatCount <= 0) {
      throw new IllegalArgumentException();
    }
    int reserved = 0;
    for(int i = 0; i < seats.length; i++) {
      if (seats[i] == null) {
        seats[i] = symbol;
        reserved++;
        if (reserved == seatCount) {
          return reserved;
        }
      }
    }
    return reserved;
  }
  
  public static void main(String[] args) {
    SeatReservation reservation = new SeatReservation(100);
    int numberOfSeat = 2;
    
    // create 10 threads (i between 0 and 9)
    // each of them executing the following code.
    
    String symbol = "" + i;
    int total = 0;
    
    int seat;
    while((seat = reservation.tryToReserve(numberOfSeat, symbol)) == numberOfSeat) {
      total += seat;
    }
    System.out.println("thread " + symbol + " total " + total);
  }
}
