Question
JAVA PROGRAM: Need code for program ! Variables for the bank model: EList = OList of Event objects (time, type) (ordered time (primary) and type
JAVA PROGRAM: Need code for program !
Variables for the bank model:
EList = OList of Event objects (time, type) (ordered time (primary) and type (secondary))
Qcust = Queue2 of Customer objects (a, s)
(a = arrival time, s = service time)
Tasks = stack of Task objects (arr, ser) (arr = arrival time, ser = service time)
Ci = customer at teller i (i = 1, 2, 3)
Bi = 1 if teller i is busy with a customer, 0 otherwise (i= 1, 2, 3)
Cust = next customer to arrive in bank (customer just read from CustArr file)
T = next task to be placed on the Tasks stack (task just read from TaskArr file)
CustArr = file of Customer
TaskArr = file of Task
TaskCurr = current task being worked on by teller 3
tt = throughtime for a customer
TT = total throughtime for all customers
Count (also called n in the example) = number of customers leaving the bank
CURR = current time
Events
- Exit from teller 1
- Exit from teller 2
- Exit from teller 3
- Ignore (Customer quits Qcust and exits bank- this is not implemented yet as an event)
- Task completion by teller 3
- Task arrival
- Customer arrival
The program begins by initializing the variables based on the given initial data.
The program then repeatedly executes the first event on the event list, until the event list is empty. To execute the next event, call the method Execute():
Execute() //method to execute the next event, at time = CURR
Event e = EList.del(EList.getData(1)) //delete and save the first event on event list
CURR = e.getTime()
Type = e.getType()
Now execute this type of event at time CURR, as follows:
To execute a type 1 exit event (customer C1 exits from teller 1 at time CURR):
- Print C1(a, s)
- Compute and print through-time tt = CURR a
- T = T + tt; Count = Count + 1;
- If Qcust is nonempty (Qcust.getSize() > 0), let C1 = Qcust.dequeue(), C1 =(a1, s1).
- Let Event next = Event(CURR + s1, 1) //prepare next exit 1 event
- EList.insert(next) //insert future type 1 exit event into the event list
- B1 = 1 (teller 1 is busy)
Type 2 exit events are done in the same way.
Type 3 exit events are a little different (customer C3 exits from teller 3 at time CURR):
Steps 1-3 are the same as for a type 1 exit event.
(*) If the Tasks stack is empty but Qcust is not empty, then continue as in step 4) above, but applied to C3 = (a3, s3), to prepare the next type 3 exit event. Set B3 = 1.
If the Tasks stack is nonempty, let TaskCurr = Tasks.pop(), TaskCurr = (arr, ser)
- Let Event next = Event(CURR + ser, 5) //prepare next task completion type 5 event
- EList.insert(next) //insert future type 5 event into the event list
- B3 = 1 (teller 3 is busy)
Type 5: Task completion event
- At time CURR, teller 3 completes TaskCurr = (arr, ser). Print the time, type of event, and TaskCurr.
- If the stack is nonempty, let TaskCurr = Tasks.pop(), and suppose TaskCurr = (arrNew, serNew). Prepare a future type 5 task completion event for time CURR + serNew, and insert this future event into the event list; set B3 = 1 (teller 3 is now bust with a new task).
- If the stack is empty and the customer queue is nonempty, then continue as in step (*) of the type 3 event.
Type 6: Task arrival
- At time CURR, task T = (arr, ser) arrives. Push this onto the stack with Tasks.push(T).
- If the stack was previously empty, then T is now the only task on the stack, so if teller 3 is free (B3 = 0), then teller 3 can begin service on this task. In this case, set TaskCurr = Tasks.pop(). Teller 3 will complete service for this task at CURR + ser, so prepare a future type 5 task completion event next = Event(Curr + ser, 5) and insert into the event list. Set B3 = 1 (teller 3 is busy with this new task.)
- If TaskArr (the task arrivals file) is not EOF, read the next task object into T,
T = (arrNew, serNew). Prepare a type 6 task arrival event for time arrNew,
Event next = Event(arrNew, 6), and insert into the event list.
Type 7 Customer arrival
The customer who is arriving is CUST(a, s), the customer last read from the file CustArr.
- Qcust.enqueue(CUST)
- If Qcust.getSize() == 1:
- If some teller is not busy, let i be the smallest number of a free teller.
- Let Ci = Qcust.dequeue(), Ci = (a, s)
- As in the type i exit event, prepare the next type i exit event for time CURR + s, and insert this event into the event list. Set Bi = 1 (busy).
- Read a new value for CUST(a, s) from CustArr (if the file is nonempty)
- Prepare the next Type 7 arrival event for time a and insert the event into the event list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started