Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program simulates a bank. Program should prompt the user asking if they

ID: 3762033 • Letter: W

Question

Write a program simulates a bank. Program should prompt the user asking if they want to run the program again. If yes, then start the program over. If no, then terminate the program. The execution phase run for 2 minutes during which time customers will arrive randomly between 2 - 6 seconds and be placed into a queue. Each customer will have a property relating to the amount of time he/she wants to spend with a teller, which is to be randomly generated to be between 2 and 5 seconds. There would be a maximum of 5 tellers to attend to the customers. When you start the simulation, each teller is occupied.You will need to generate a random time for each of the first 5 customers occupying the tellers at the begining of the 2 minutes simulation. As they finish attending a customer (based upon the amount of time associated with each customer), that teller becomes available for the next customer in the queue. As a customer is removed from the queue and sent to an "available" teller, then their availability is set to "False". Customers are allocated to any one of the 5 tellers that becomes available, and so on... until the time of 2 minutes for the simulation is finished. If after 2 minutes, there are still customers in the queue, we would discard them, but still count them in the total count of customers that visited the bank. Also add into the total count of customer the first five customers that the tellers started out with as well as to the individual teller's total. Finally display on the screen (at the end of each execution):

1.The total amount of customers that visited the bank for that 2 minutes.

2.The total amount of customers that each teller helped.

3.The total amount of time that each teller was occupied.

4.The total amount of customers that did not get to see a teller.

Explanation / Answer

import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Bank
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while(true)
{
System.out.println("Are you likely to run the bank simulation? Enter "yes" or "no": ");
String input = scanner.nextLine();
input.toLowerCase();
if (input.equals("yes") || input.equals("y"))
{
Runnable helloRunnable = new Runnable()
{
Random rand = new Random();
Queue<Integer> queue = new LinkedList<Integer>();
boolean teller1,teller2,teller3,teller4,teller5 = false;
boolean[] tellersArray = {teller1, teller2, teller3, teller4, teller5};
int[] tellersArray2 = {(rand.nextInt(5 - 2) + 2),(rand.nextInt(5 - 2) + 2),(rand.nextInt(5 - 2) + 2),(rand.nextInt(5 - 2) + 2),(rand.nextInt(5 - 2) + 2)};
int i = 0;
int a, b, c, d, e;
int customersServed1, customersServed2, customersServed3, customersServed4, customersServed5 = 0;
int occupiedTime1, occupiedTime2, occupiedTime3, occupiedTime4, occupiedTime5 = 0;
int v, w, x, y, z = 1;
public void run()
{
if(i == 120)
{
System.out.println("The amount of customers that visited the bank was: " + (customersServed1 + customersServed2+ customersServed3 + customersServed4 + customersServed5 + 5 + queue.size()) + " customers.");
System.out.println("The amount of customers that each teller helped was: ");
System.out.println("Teller 1: " + (customersServed1 + 1));
System.out.println("Teller 2: " + (customersServed2 + 1));
System.out.println("Teller 3: " + (customersServed3 + 1));
System.out.println("Teller 4: " + (customersServed4 + 1));
System.out.println("Teller 5: " + (customersServed5 + 1));
System.out.println("For a total of " + (customersServed1 + customersServed2 + customersServed3+ customersServed4 + customersServed5 + 5) + " customers.");
System.out.println("The amount of time the tellers were occupied was: " + (occupiedTime1 + occupiedTime2 + occupiedTime3+ occupiedTime4 + occupiedTime5) + " seconds.");
System.out.println("The amount of customers that didn't get to see a teller was : " + queue.size() + " customers");
System.out.println("Ending simulation...");
System.exit(0);
}
else
{
if(rand.nextInt(4) < 6)
{
int time = (rand.nextInt(5 - 2) + 3);
queue.add(time);
}
while(v == 1)
{
a = i;
v = 0;
}
if ((i - a) >= tellersArray2[0])
{
tellersArray[0] = true;
if (tellersArray[0] == true && queue.isEmpty() == false)
{
occupiedTime1 += tellersArray2[0];
tellersArray2[0] = queue.poll();
v = 1;
customersServed1++;
}
}
while(w == 1)
{
b = i;
w = 0;
}
if ((i - b) >= tellersArray2[1])
{
tellersArray[1] = true;
if (tellersArray[1] == true && queue.isEmpty() == false)
{
occupiedTime2 += tellersArray2[1];
tellersArray2[1] = queue.poll();
w = 1;
customersServed2++;
}
}
while(x == 1)
{
c = i;
x = 0;
}
if ((i - c) >= tellersArray2[2])
{
tellersArray[2] = true;
if (tellersArray[2] == true && queue.isEmpty() == false)
{
occupiedTime3 += tellersArray2[2];
tellersArray2[2] = queue.poll();
x = 1;
customersServed3++;
}
}
while(y == 1)
{
d = i;
y = 0;
}
if ((i - d) >= tellersArray2[3])
{
tellersArray[3] = true;
if (tellersArray[3] == true && queue.isEmpty() == false)
{
occupiedTime4 += tellersArray2[3];
tellersArray2[3] = queue.poll();
y = 1;
customersServed4++;
}
}
while(z == 1)
{
e = i;
z = 0;
}
if ((i - e) >= tellersArray2[4])
{
tellersArray[4] = true;
if (tellersArray[4] == true && queue.isEmpty() == false)
{
occupiedTime5 += tellersArray2[4];
tellersArray2[4] = queue.poll();
z = 1;
customersServed5++;
}
}
i++;
if(queue.size() == 1)
{
System.out.println("There is " + queue.size() + " person currently in the queue.");
}
else
{
System.out.println("There are " + queue.size() + " people currently in the queue.");
}
System.out.println("There are " + (120 - i) + " seconds left in the simulation.");
System.out.println("--------");
}   
}
};
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(helloRunnable, 0, 1, TimeUnit.SECONDS);
}
else if (input.equals("no") || input.equals("n"))
{
System.out.println("Ending program...");
System.exit(0);
}
else
{
System.out.println("Incorrect input. Enter "yes" or "no": ");
}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote