Question: please make it as soon as possible the code should be in jaava only Assume a scenario of railway reservation system where two passengers are

please make it as soon as possible the code should be in jaava only
Assume a scenario of railway reservation system where two passengers are trying to book a ticket from a certain source to destination in a same train. Both the passengers are trying to book the tickets in the same time. Think that only one berth is available in the train and both the passengers are asking for the same berth. Design a Java program using thread synchronization so that only one ticket is allocated to one person at a time. To design program take a class named as "Train_Ticket" that implements runnable. Take two variables such as total_berths_available and berths_requested. Create two threads t1 and 12. When t1 enters the run method, it checks the "total_berths_available" and allot it to the first person. After the allocation of the berth the thread t1 enters try{} block inside the run method and goes to sleep for 5 seconds. During this sleep duration the ticket will be printed in the printer. The program can only compile successfully if you can use a synchronized block effectively. Sample Output Available berths= 1 1 Berth reserved for First Person Available berths= 0 Sorry! No berths available
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
