-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSimulation.java
More file actions
64 lines (56 loc) · 1.6 KB
/
BankSimulation.java
File metadata and controls
64 lines (56 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
/**
* This class implements a bank simulation.
*
* @author Wei Tsang
* @version CS2030S AY25/26 Semester 2
*/
class BankSimulation extends Simulation {
/**
* The availability of counters in the bank.
*/
private Counter[] counters;
/**
* The list of customer arrival events to populate
* the simulation with.
*/
private Event[] initEvents;
/**
* Constructor for a bank simulation.
*
* @param sc A scanner to read the parameters from. The first
* integer scanned is the number of customers; followed
* by the number of service counmers. Next is a
* sequence of (arrival time, service time) pair, each
* pair represents a customer.
*/
public BankSimulation(Scanner sc) {
initEvents = new Event[sc.nextInt()];
int numOfCounters = sc.nextInt();
int maxQLen = sc.nextInt();
Queue queue = new Queue(maxQLen);
Bank bank = new Bank(numOfCounters, queue);
for (int i = 0; i < numOfCounters; i++) {
bank.addCounter(new Counter());
}
int id = 0;
while (sc.hasNextDouble()) {
double arrivalTime = sc.nextDouble();
double serviceTime = sc.nextDouble();
int customerTask = sc.nextInt();
Customer customer = new Customer(serviceTime, customerTask);
initEvents[id] = new ArrivalEvent(arrivalTime, customer, bank);
id++;
}
}
/**
* Retrieve an array of events to populate the
* simulator with.
*
* @return An array of events for the simulator.
*/
@Override
public Event[] getInitialEvents() {
return initEvents;
}
}