In Java, complete the following:
During the lunch hour, the ATM machine in a large office complex is in heavy demand. Customers complain that the waiting time is much too long. The local bank considering the addition of a second ATM machine. But first, the bank needs a few statistics to justify the cost of adding a second ATM machine. Using a Queue, simulate a waiting line at the ATM machine for a period of one hour. Make the following assumptions:
At the end of an hour; display the following summary statistics;
Assume that the ATM is available when the simulation begins and that no customers are waiting.
Design a class that models an ATM customer
The algorithm that simulates an ATM waiting line uses a loop that ticks through a 60min simulation
Solution:
...............................................................................................................................................................
// Customer.java
public class Customer {
// attributes
private int arrivalTime;
private int serviceTime;
private int finishTime;
// constructor to initialize all fields to 0
public Customer() {
arrivalTime = 0;
serviceTime = 0;
finishTime = 0;
}
// constructor taking arrival and service times
public Customer(int arrivalTime, int serviceTime) {
this.arrivalTime = arrivalTime;
this.serviceTime = serviceTime;
}
// getters and setters
public int getArrivalTime() {
return arrivalTime;
}
public void setArrivalTime(int arrivalTime) {
this.arrivalTime = arrivalTime;
}
public int getServiceTime() {
return serviceTime;
}
public void setServiceTime(int serviceTime) {
this.serviceTime = serviceTime;
}
public void setFinishTime(int finishTime) {
this.finishTime = finishTime;
}
public int getFinishTime() {
return finishTime;
}
}
// ATMSimulation.java
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
public class ATMSimulation {
public static void main(String[] args) {
// creating a Random object for random number generation
Random random = new Random();
// creating a Queue of Customer objects
Queue<Customer> customerQueue = new LinkedList<Customer>();
// initializing required variables
// a variable to denote if the ATM is currently free, if this is 0, it
// means that the ATM is free, else it will take currentAtmStatus
// minutes to be free
int currentAtmStatus = 0;
// number of customers served
int numCustomersServed = 0;
// total waiting time
int totalWaitingTime = 0;
// looping for 60 times
for (int i = 0; i < 60; i++) {
int newCustomers = 0;
// generating a number between 0 and 99
int probability = random.nextInt(100);
// if the number is less than 10, 2 new customers are added
if (probability < 10) {
newCustomers = 2;
} else if (probability >= 10 && probability < 50) {
// number is greater than 10 and less than 50, 1 new customer
// is added
newCustomers = 1;
} else {
// in all other cases (50%), no customers are added
newCustomers = 0;
}
// looping and adding newCustomers number of customers
for (int j = 0; j < newCustomers; j++) {
// creating a customer with i arrival time and a random service
// time between 1 and 3
Customer c = new Customer(i, random.nextInt(3) + 1);
// adding to queue
customerQueue.add(c);
}
// now checking if queue is empty and ATM is free
if (!customerQueue.isEmpty() && currentAtmStatus == 0) {
// removing oldest customer in the queue
Customer c = customerQueue.remove();
// adding his service time to currentAtmStatus, so that the ATM
// will be free only after currentAtmStatus minutes from now
currentAtmStatus += c.getServiceTime();
// setting finish time
c.setFinishTime(i + c.getServiceTime());
// finding waiting time, and adding to total waiting time
totalWaitingTime += c.getFinishTime() - c.getArrivalTime()
- c.getServiceTime();
// incrementing number of customers served
numCustomersServed++;
}
// every minute passes, currentAtmStatus is decremented (if it is
// above 0)
if (currentAtmStatus > 0) {
currentAtmStatus--;
}
}
//finally displaying all stats
System.out.println("Number of customers served: " + numCustomersServed);
//finding average waiting time
double avgWaitingTime = (double) totalWaitingTime / numCustomersServed;
System.out.printf("Average waiting time (minutes): %.2f\n",
avgWaitingTime);
System.out.println("Number of customers still in queue "
+ "at the end of simulation: " + customerQueue.size());
}
}
/*OUTPUT1*/
Number of customers served: 33
Average waiting time (minutes): 8.33
Number of customers still in queue at the end of simulation: 10
/*OUTPUT2*/
Number of customers served: 27
Average waiting time (minutes): 13.26
Number of customers still in queue at the end of simulation: 7
/*OUTPUT3*/
Number of customers served: 29
Average waiting time (minutes): 4.76
Number of customers still in queue at the end of simulation: 4
In Java, complete the following: During the lunch hour, the ATM machine in a large office...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...
Please answer using stochastic operations principles Cars arrive at a rate of 10 per hour in a single-server drive-in restaurant. Assume that the teller serves vehicles with a rate exponentially distributed with a mean of 4 minutes per car (ie, a rate of 1 car every 4 minutes). Answer the following questions: (a) What is the probability that the teller is idle? (b) What is the average number of cars waiting in line for the teller? (A car that is...
C++ Sample run might look like this: How many minutes should the simulation run? 10 Running simulation for 10 minutes. minute 1: nothing happens minute 2: customer 1 arrives and will need 3 minutes to check out minute 3: nothing happens minute 4: customer 2 arrives and will need 1 minute to check out minute 5: customer 3 arrives and will need 1 minute to check out minute 5: customer 1 has checked out minute 6: customer 2 has checked...
Customers arrive at a bank that has 1 teller and they wait in line on a first-come, first-sorved basis. Customers arrive according to a Poisson process with a rate of 14.5 per hour. It takes on average 4 minutes for a customer to be served by the tellor. No customer leaves without going through service with the teller. The standard deviation of the service time is 2 minutes. What is the average time a customer spends waiting in line? (Enter...
4. When John enters the bank office, there are four customers waiting in line and one customer is being served. There is a single clerk and the service time is exponentially distributed with λ-10 customer per hour, independent of everything else. (a) (2 points) What is the average service time per customer? (b) (4 points) What is the distribution of John's waiting time? (c) (4 points) Calculate the expected value and variance of John's waiting time. (d) (10 points) It...
4. When John enters the bank office, there are four customers waiting in line and one g served. There is a single distributed with A10 customer per hour, independent of everything else. (a) (2 points) What is the average service time per customer? (b) (4 points) What is the distribution of John's waiting time? (c) (4 points) Calculate the expected value and variance of John's waiting time (d) (10 points) It has been 15 minutes and now John is the...
Please fill in all question marks!!!! Problem 15-25 (Algorithmic) Burger Dome sells hamburgers, cheeseburgers, French fries, soft drinks, and milk shakes, as well as a limited number of specialty items and dessert selections. Although Burger Dome would like to serve each customer immediately, at times more customers arrive than can be handled by the Burger Dome food service staff. Thus, customers wait in line to place and receive their orders. Suppose that Burger Dome analyzed data on customer arrivals and...
Queues This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program. Step 1 - Create a new project in Netbeans Use the following naming convention: “Module4_Lastname_Assignment1”. Step 2 - Build a solution You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new...
Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I have so far just basically adds customers to the queue and prints when they arrive. I am struggling with how to implement a way of keeping track of when a given customer finishes(I will attach what I have so far). I had already created queue and node classes (with headers and cpp files) that I modified in my attempt. I would be very grateful...
7.4 During lunch hour, customers arrive at a fast-food restaurant at the rate of T20 customers per hour. The restaurant has one line, with three workers taking food orders at independent service stations. Each worker takes an exponentially dis- tributed amount of time-on average 1 minute-to service a customer. Let X, denote the number of customers in the restaurant (in line and being serviced) at time t. The process (Xt)PO Is a continuous-time Markov chain. Exhibit the generator matrix