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 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 to 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 and ms
Go back and inform the customer the transaction is done
There are supposed to be 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 is going to the bank.
Customer is getting in line.
Customer is selecting a teller.
Customer goes to Teller
Customer introduces itself to Teller
Teller is serving Customer
Customer asks for a withdrawal transaction.
Teller is handling the withdrawal transactic
Teller is going to the manager.
Teller is getting the manager's permission.
Teller is got the manager's permission.
Teller is going to the safe.
Teller is in the safe.
Customer is going to the bank.
Customer is getting in line.
Customer is selecting a teller.
Customer goes to Teller
Customer introduces itself to Teller
Teller is serving Customer
Customer asks for a deposit transaction.
Teller is handing the deposit transaction.
Teller will let everyone know it is ready to serve
Im testing it with customers to be able to debug it more efficiently.
Im using an array of threads to control the 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.
Im 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
