The project must be done individually. No exceptions.

You are asked to synchronize the threads of the following story using semaphores and operations on semaphores. Do NOT use busy waiting.

The initial regular weight for project 2 (as a programming project) was 6%. You have the following choices:

1. You can submit a pseudo-code implementation; in that case the project will have a weight of 5% instead of 6 % (you lose 1% on the weight).
Due Date: Wed. May 13

Or

2. You can submit a java-code implementation; in that case the project weight will be 7% instead of 6% (you get 1% EC on project 2’s weight). I wish I could give you more but too many of you are plagiarizing.

Due Date: Tue. May 19

DO NOT SUBMIT BOTH TYPES OF IMPLEMENTATION: EITHER YOU SUBMIT THE PSEUDOCODE, OR YOU SUBMIT THE JAVA-CODE.

Directions: Synchronize the passenger, kiosk-clerk, flight attendant, and clock threads in the context of the problem described below. Please refer to and read the project notes carefully, tips and guidelines before starting the project.
***********************************************************************************************************
Passengers of Flight CS-340 to Purell-Wonderland, NY arrive at the airport 3 hours before departure (use

the problem described below. Please refer to and read the project notes carefully, tips and guidelines
before starting the project.
***********************************************************************************************************

Passengers of Flight CS-340 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 counter to have their boarding passes printed.

Unfortunately, due to budget cuts, the airline can only maintain 2 check-in counters at this time. To avoid crowding at the check-in counters, the airline asks passengers to form lines ( crowding at the check-in counters, the airline asks passengers to form lines (wait). On which line the passenger should be decided randomly.

At each counter, there is a check-in clerk who will assist the passengers. Passengers will receive their boarding pass from the check-in clerk with a seat and zone number printed on it. The check-in clerk will generate this number and assign it to the passenger. The seat number is a random number between 1 and 30 with a corresponding zone number; passengers with seat numbers between 1 and 10 are in Zone 1, passengers with seat numbers between 11 and 20 are in Zone 2, passengers with seat numbers between 21 and 30 are in Zone 3. Note that the aircraft holds only 30 passengers and is split up into 3 zones. (Output a message to the screen with the passenger’s seat and zone information).

After all passengers receive their boarding pass, the check-in clerks are done for the day (they terminate)

Once the passengers arrive at the gate, they take a seat and wait for the flight attendant to call for passengers to board.

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 first zone (maybe you would like to have implement different semaphores, one for each zone). At the door, the passengers are asked to wait in line until all others have boarded. 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.

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 wait for the flight en route to their destination.

Two hours pass, and the plane prepares for landing. The flight attendant signals the passengers that the flight has landed.

The plane lands and the passengers wait for the go-ahead to disembark the plane. Passengers are asked 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); the order in which they leave is Thread-1, Thread-3, Thread-4, Thread-2;

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).

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.
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.
Initial values:
numPassengers = 30
groupNum = 4
counterNum = 3

1. Pseudo-code implementation
You are asked to synchronize the threads of the story using semaphores and operations on semaphores. Do NOT use busy waiting.
Use pseudo-code similar to the one used in class (NOT java pseudo-code).
Mention the operations that can be simulated by a fixed or random sleep_time.
Your documentation should be clear and extensive.
Explain the reason for each semaphore that you used in your implementation.
Explain each semaphore type and initialization.
Discuss the possible flows of your implementation. Deadlock is not allowed.
2. java-code implementation
The number of passengers should be read as a command line argument.
Using Java programming, synchronize the threads, in the context of the problem. Closely follow the implementation requirements. The synchronization should be implemented through
Java semaphores and operations on semaphores (acquire and release)
For Mutual Exclusion implementation use Mutex semaphores, not volatile variables.
For semaphore constructors, use ONLY:
Semaphore(int permits, boolean fair)
Creates a Semaphore with the given number of permits and the given fairness setting.
In methods use ONLY: acquire(), release(); You can also use:
getQueueLength()
Returns an estimate of the number of threads waiting to acquire.
hasQueuedThreads()
Queries whether any threads are waiting to acquire.
DO NOT USE ANY OF THE OTHER METHODS of the semaphore’s class, besides the ones mentioned above.
Any wait must be implemented using P(semaphores) (acquire).
Any shared variable must be protected by a mutex semaphore such that Mutual Exclusion is implemented.
Document your project and explain the purpose and the initialization of each semaphore.
DO NOT use synchronized methods (beside the operations on semaphores).
Do NOT use wait( ), notify( ) or notifyAll( ) as monitor methods. Whenever a synchronization issue can be resolved use semaphores and not a different type of implementation.
You should keep the concurrency of the threads as high as possible, however the access to shared structures has to be done in a Mutual Exclusive fashion, using a mutex semaphore.
Many of the activities can be simulated using the sleep(of a random time) method.
Use appropriate System.out.println( ) statements to reflect the time of each particular action done by a specific thread. This is necessary for us to observe how the synchronization is working.
Submission similar to project1. Name your project: YourLastname_Firstname_CS340_p2
Upload it on Blackboard.
Do not submit any code that does not compile and run. If there are parts of the code that contain bugs, comment it out and leave the code in. A program that does not compile nor run will not be graded.
Closely follow all the requirements of the project’s description.
The main method is contained in the main thread. All other thread classes must be manually created 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). DO NOT create packages.
The project asks that you create different types of threads. There is more than one instance of a thread. No manual specification of each thread's activity is allowed (e.g. no
Passenger5.goThroughTheDoor())
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);
}
It is recommended that you initialize the time at the beginning of the main method, so that it is
unique to all threads.
There should be output messages that describe how the threads are executing. Whenever you
want to print something from a thread use: msg("some message about what action is
simulated");

NAME YOUR THREADS. 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 its 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.
A command line argument must be implemented to allow changes to the nPassenger variable.
Javadoc is not required. Proper basic commenting explaining the flow of the program, selfexplanatory variable names, correct whitespace and indentations are required.
Setting up project/Submission:
For those that use Eclipse:
Name your project as follows: LASTNAME_FIRSTNAME_CSXXX_PY, where LASTNAME is your last
name, FIRSTNAME is your first name, XXX is your course, and Y is the current project number.
For example: Doe_John_CS340_p2
To submit:
-Right click on your project and click export
-Click on General (expand it)
-Select Archive File
-Select your project (make sure that .classpath and .project are also selected)
-Click Browse, select where you want to save it to and name it as
LASTNAME_FIRSTNAME_CSXXX_PY
-Select Save in zip format (.zip)
-Press Finish
PLEASE UPLOAD YOUR FILE ON BLACKBOARD IN THE CORRESPONDING COLUMN.
The project must be done individually with no use of other sources including Internet.
No plagiarism, no cheating.