Question: in java use the Thread and Semaphore classes Instructions for Teller and Customer: There are three ( 3 ) tellers. When a teller thread is

in java use the Thread and Semaphore classes
Instructions for Teller and Customer:
There are three (3) tellers.
When a teller thread is created it should be given an unique id.
Wait until customer gives the transaction
If the transaction is a Withdraw, go to the manager for permission.
To represent this interaction, the teller thread should block for a random duration from 5 to30 ms .
Go to the safe, waiting for it if it is occupied by two tellers
In the same, the teller will physically perform the transaction
represent this by blocking for a random duration of between 10 and 50 ms .
Go back and inform the customer the transaction is done
There are supposed to be 50 customers in total.
The customer will decide (at random) what transaction to perform: Deposit or Withdrawal.
The customer will enter the bank (The door only allows two customers to enter at a time).
The customer will get in line. If there is a teller ready to serve, the customer should immediately go to the first ready teller. otherwise, the customer should wait until called and then go to a ready teller.
The customer will introduce itself (give its id) to the teller.
Tell the teller the transaction.
Will wait for the teller to complete the transaction.
The customer will leave the bank (and the simulation).
Example Output:
Customer 7 is going to the bank.
Customer 7 is getting in line.
Customer 7 is selecting a teller.
Customer 7 goes to Teller 0.
Customer 7 introduces itself to Teller 0.
Teller 0 is serving Customer 7.
Customer 7 asks for a withdrawal transaction.
Teller 0 is handling the withdrawal transactic
Teller 0 is going to the manager.
Teller 0 is getting the manager's permission.
Teller 0 is got the manager's permission.
Teller 0 is going to the safe.
Teller 0 is in the safe.
Customer 4 is going to the bank.
Customer 4 is getting in line.
Customer 4 is selecting a teller.
Customer 4 goes to Teller 1.
Customer 4 introduces itself to Teller 1.
Teller 1 is serving Customer 4.
Customer 4 asks for a deposit transaction.
Teller 1 is handing the deposit transaction.
Teller will let everyone know it is ready to serve
I'm testing it with 5 customers to be able to debug it more efficiently.
I'm using an array of threads to control the 3 tellers but I am having trouble checking when one is open or busy with a customer and the output shows its always using the same teller for some reason.
I'm using java. Please don't chatgpt this.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!