Passengers of Flight CS-344715 to Purell-Wonderland, NY arrive at the airport 3 hours before departure (use sleep(random_time) to simulate arrival). Upon their arrival, they go straight to the check-in kiosk to print their boarding passes.

Unfortunately, due to budget cuts, the airline can only maintain two checking counters at this time. To avoid crowding around the highly sought-after checking counters, the airline asks passengers to form lines of no more than a few passengers at each counter (determined by counterNum) Each passenger must block on a different object. Use a similar approach as the one in rwcv.java. Those not able to get on a line for a counter are asked to stand by (wait). To ensure fairness to those that arrived early, passengers should be helped in the order in which they arrived (ensure FCFS among passengers).

At each checking counter, there is a checking counter-clerk who will assist the passengers. While assisted, the passengers receive their boarding pass with their seat and zone number printed on it. Note that the aircraft holds only 30 passengers and is split up in 3 zones. Passengers are assigned a random seat number between 1-30 and a corresponding zone number; passengers with seat numbers between 1 and 10 passengers are in Zone 1, passengers with seat numbers between 11 and 20 are in Zone 2, etc. The number is generated by the clerk and assigned to the passenger. (Output a message to the screen with the passenger's seat and zone information).

Once the passenger arrives at the gate, they take a seat and wait for the flight attendant to call for passengers to board (passengers belonging to the same zone will all block on the same object. So there will be 3 different objects for 3 different zones)

A half an hour before the plane departs, the flight attendant begins to call passengers up to the door of the jet bridge. The flight attendant calls the zones one by one.

For example, when it comes to zone 1, the flight attendant calls all passengers of zone 1 (use notifyAll) and asks the passengers to scan their boarding pass and get to the airplane's door. This must be done in a mutual exclusion way. Use synchronized methods. When all have arrived, the passengers enter the plane in groups (determined by groupNum), so that passengers can comfortably stow their belongings and take their seats. You dont necessarily need to use separate notifications objects, rather use a variable that will be updated. When that variable becomes groupNum, allow first the passengers part of that group to arrange their luggage and take a seat, and next a new groupNum of passengers will be able to get inside the plane.

The flight attendant calls each of the remaining zones the same way.

After all zones have boarded, the flight attendant makes an announcement indicating that the door of the plane has closed. All passengers that arrive at the gate after this announcement are asked to rebook their flight and return home (these threads terminate). All other passengers get entertained on the flight in transit to their destination (use wait).

Two hours pass, and the plane prepares for landing. The flight attendant notifies the passengers with an announcement over the loud speaker.

The plane lands and the passengers wait for the go-ahead to disembark the plane. When the flight attendant turns off the seatbelt light, passengers are asked (notified) to leave the plane in ascending order of their seat number (let's say on the plane you have Thread- 3 (seat 2), Thread-4 (seat 3), Thread-2 (seat 4) and Thread-1 (seat 1); Make sure that the passengers are notified in the specified order.

The passengers disperse after the flight and go off to their respective destinations (threads terminate). The flight attendant cleans the aircraft, and is the last to leave after all the passengers(thread terminates). The last passenger to leave will notify the flight attendant.

A few things to note:

1. In order to keep track of time, there needs to be a clock thread. The clock thread signals the flight attendant when it's time to start the boarding process and disembark the plane. The clock will sleep for a fixed amount of time before and in between these two events. After all passengers have disembarked, the clock will announce that it is terminating and then terminate. The clock thread doesnt call wait.

2. Make it very clear which passenger thread departs the plane and what their seat number is. A message indicating departure might look like this:

Passenger-1: is in seat 6 and departs the plane.

Directions: Synchronize the passenger, flight attendant, checking counter clerk and clock threads in the context of the problem described above. The number of passengers should be entered as a command line argument.

Do NOT use busy waiting. If a thread needs to wait, it must wait on an object (class object or notification object). You can use synchronized methods and blocks, wait(), notify() and notifyAll().

DO NOT use other synchronization tools (like: Executors, Concurrent Collections, Lock Objects....) than the ones covered in class.

3. Initial values: numPassengers = 30 groupNum = 4 counterNum = 3

Use the age( ) method and appropriate println statements to show how synchronization works. It is important to have print statements before, inside, and after critical sections. State clearly what the current thread executing the print statement is doing. Also, be sure to include the name of the thread and a timestamp relative to the start time of the program.

Choose the appropriate amount of time(s) that will agree with the content of the story. I haven't written the code for this project yet, but from the experience of grading previous semesters projects, a project should take somewhere between 50 seconds and at most 1 minute and 34 to run and complete.

Follow the story closely and cover the requirements of the project's description. Besides the synchronization details provided there are other synchronization aspects that need to be covered. You can use synchronized methods or additional synchronized blocks to make sure that mutual exclusion over shared variables is satisfied.

The Main class is run by the main thread. The other threads must be manually specified by either implementing the Runnable interface or extending the Thread class. Separate the classes into separate files. Do not leave all the classes in one file. Create a class for each type of thread.

Add the following lines to all the threads you make:

public static long time = System.currentTimeMillis();
public void msg(String m) {
System.out.println("["+(System.currentTimeMillis()-time)+"] "+getName()+": "+m); }

There should be printout messages indicating the execution interleaving. Whenever you want to print something from that thread use: msg("some message here");

NAME YOUR THREADS or the above lines that were added would mean nothing. Here's how the constructors could look like (you may use any variant of this as long as each thread is unique and distinguishable):

// Default constructor
public RandomThread(int id) {
setName("RandomThread-" + id); }

Design an OOP program. All thread-related tasks must be specified in their respective classes, no class body should be empty.

DO NOT USE System.exit(0); the threads are supposed to terminate naturally by running to the end of their run methods.

Javadoc is not required. Proper basic commenting explaining the program flow, self- explanatory variable names, correct whitespace and indentations is required.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.