packagetheatre;publicclassReservations{inttotalSeats=10;intreservedSeats=8;publicsynchronizedintcheckFreeSeats(){if(totalSeats-reservedSeats>0){//if there are free seatsSystem.out.println("reserved = "+reservedSeats);returnreservedSeats;//return the number of reserved seats}else{return0;}}//the integer represent the ith seat taken. if it is -1, the ticket was not bought.publicsynchronizedintbuyTicket(){//if there are free seats...if(checkFreeSeats()>0){//Simulate some processing time/* try { Thread.sleep(10000); } catch (InterruptedException e) { throw new RuntimeException(e); }*/reservedSeats++;System.out.println("Updated to: "+reservedSeats);returnreservedSeats;}else{return-1;}}}