Write a Java program to simulate a bank teller system, with a number of customers and a number of tellers.
Each customer is handed a unique customer number, in sequential order. Whenever a teller is free, they call the next customer to be served, in order of customer number, by invoking a private method assignCustomer() that returns a customer number. After serving customer number X, the teller prints out a message saying they have served the customer number X.
You need to print diagnostics as indicated in the sample output included (see below). Use
import java.util.concurrent.*;
at the start of the program and use
long threadId = Thread.currentThread().getId()%nTellers +1;
to get the teller number in the appropriate place.
You need to create a Bank class whose constructor takes two integers as parameters, the number of tellers and the number of customers for the day.
Write two implementations in Java:
An implementation that does not protect assignCustomer() and allows race conditions where two tellers try to serve the same customer. Submit this as a file Bank-race.java.
A correct implementation to ensure that each customer is served by a single teller, the tellers together serve all customers, and, for each teller, the customer numbers that they serve are in ascending order. Submit this as a file Bank-norace.java.
Included is UseBank.java, a program to test your Bank class, and bank-race-out.txt and bank-norace-out.txt, the outputs generated by sample runs with and without race conditions.
Note: We will test your solutions using UseBank.java. Do not add any package declarations. Do not submit a main() method as part of your solution. Any submissions that violate these guidelines risk not being graded
Write Rust code for the following configuration of five concurrent processes communicating through message passing channels.
Job generator: The job generator generates a sequence of jobs, each with some measure of cost. The number of jobs is random and the cost of each job is a random positive integer. The end of the sequence is signalled by a job of cost 0 (zero). The job generator passes on the cost of each job as a separate message over a channel to the job scheduler.
Job scheduler: The scheduler receives the jobs from the generator. Each job is passed to one of the machines by sending the cost of the job as a message over a channel. The aim is to balance the overall load processed by each machine — i.e., the total cost of the jobs processed by each machine should be as similar as possible.
Two machines: Each machine receives a sequence of jobs as messages from the scheduler and passes on this sequence to the report writer. Both machines are connected through the same channel to the report writer (recall that Rust has multiple producer, single consumer channels).
Report writer: The report writer receives information from both machines about the jobs they have processed. After all jobs have been processed, the report writer should print the total cost of the jobs processed by each machine.
Note: All processes should gracefully exit after the last job is processed.
Submit your Rust solution as a file scheduler.rs with a suitably defined main() function that creates all five concurrents processes and lets them run till termination.
Submissions with compilation errors will not be graded.
Late submissions will not be graded.