Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on these instructions: Customers at airlines and banks typically join a single queue. They move through the queue and eventually take their place at

Based on these instructions: Customers at airlines and banks typically join a single queue. They move through the queue and eventually take their place at one of the open counters or "service areas." Each customer then conducts his/her business and leaves. The situation is diagrammed here:
Suppose an airline or a bank wants to measure the wait-times to serve each customer, from the minute they enter to the minute they leave. The airline hires you to program a simulation of the situation.
You need one queue.
You need an array of the correct size to represent the service areas.
You need to know how often, the frequency per minute, that customers join the queue.
You need to know how long it takes (a random number) to conduct the customer's business after they arrive at the service area. We will count each minute down to 0, after which the customer leaves.
You need to store the time at which the customer entered the queue.
You need to calculate how long the customer spent getting served (the total wait time), from the minute they entered to the minute they left.
You need to know how long to run the simulation.
For each minute write to a file:
Each minute, starting from 0.
The service areas serving their customers. Each customer shows the time remaining until they complete their business and leave.
The queue with its customers, showing the time they need to complete their business.
The total customers served.
The average wait time per customer.
The longest wait time of any customer.
The length of the longest queue of customers.
Customers in a Queue Simulation!
How many service areas? 3
How long, in minutes, should the simulation run? 20
Total customers served =9
Average wait time =7.5
Longest wait time =12
Longest queue =5
You need to generate two random numbers in this lab:
whether a customer joins the queue during that minute. Let's set the frequency at an 80% chance per minute.
how long it takes to conduct the customer's business after they get to the service area. Let's generate a random integer between 3 and 9 minutes, inclusive.
The Customer class
It seems like a Customer class would be a good way to model the situation.
Complete this code:
4 import java.util.*;
5 import java.io.*;
6 public class SeniorsFirst
7{
8 public static final int CUSTOMERS_PER_MINUTE =2;
9
10 public static void main(String[] args)
11{
12 PrintWriter outfile = setUpFile();
13
14 System.out.println("Seniors First Simulation! ");
15 Scanner kb = new Scanner(System.in);
16 System.out.print("How many cashiers? ");
17 int number_of_cashiers = kb.nextInt();
18 System.out.print("How long, in minutes, should the simulation run? ");
19 int time = kb.nextInt();
20
21 waitTimes(time, number_of_cashiers, outfile); //run the simulation
22}
23
24 public static PrintWriter setUpFile()
25{
26 PrintWriter outfile = null;
27 try
28{
29 outfile = new PrintWriter(new FileWriter("customerWaitTimes.txt"));
30}
31 catch(IOException e)
32{
33 System.out.println("File not created");
34 System.exit(0);
35}
36 return outfile;
37}
38
39 public static void outfileCashiersAndQueues(PrintWriter outfile, int min, ArrayList> cashier)
40{
41 outfile.println("minute "+ min +": ");
42 for( Queue q : cashier )
43{
44 outfile.print("");
45 if(q.isEmpty()) outfile.print("null");
46 for( Customer c : q )
47 outfile.print( c.toString()+"");
48 outfile.println();
49}
50}
51
52 public static double calculateAverage(int totalMinutes, int customers)
53{
54 return (int)(1.0* totalMinutes/customers *100)/100.0;
55}
56
57 public static void waitTimes(int time, int number_of_cashiers, PrintWriter outfile)
58{
59 int customers =0;
60 int customersCheckedOut =0;
61 String[] classes = new String[]{"Senior", "Junior", "Sophomor", "Freshman"};
62 int[] served = new int[]{0,0,0,0};
63 int[] longestWait = new int[]{0,0,0,0};
64 int[] totalWait = new int[]{0,0,0,0};
65
66 ArrayList> cashiers = new ArrayList<>();
67 for(int i=0; i());
69/***************************************
70 Write your code for the simulation.
71 call outfileCashiersAndQueues() to write the queues to the file.
72**********************************/
78/* report the results to the screen in table form, like this:
79 Customer Total Longest Average Wait
80 Senior 23104.434782608695652
81 Junior 1840

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions

Question

How does a prospective exporter choose an export market?

Answered: 1 week ago

Question

Write the numbers of base 12 up to \(1_{00}^{4}\).

Answered: 1 week ago

Question

External vs. internal motivation

Answered: 1 week ago

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago