Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA CODE: Need code for the execute method: Variables for the bank model: EList = OList of Event objects (time, type) (ordered time (primary) and

JAVA CODE: Need code for the execute method:

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

  1. Exit from teller 1
  2. Exit from teller 2
  3. Exit from teller 3
  4. Ignore (Customer quits Qcust and exits bank- this is not implemented yet as an event)
  5. Task completion by teller 3
  6. Task arrival
  7. 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):

  1. Print C1(a, s)
  2. Compute and print through-time tt = CURR a
  3. T = T + tt; Count = Count + 1;
  4. If Qcust is nonempty (Qcust.getSize() > 0), let C1 = Qcust.dequeue(), C1 =(a1, s1).
  1. Let Event next = Event(CURR + s1, 1) //prepare next exit 1 event
  2. EList.insert(next) //insert future type 1 exit event into the event list
  3. 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)

  1. Let Event next = Event(CURR + ser, 5) //prepare next task completion type 5 event
  2. EList.insert(next) //insert future type 5 event into the event list
  3. B3 = 1 (teller 3 is busy)

Type 5: Task completion event

  1. At time CURR, teller 3 completes TaskCurr = (arr, ser). Print the time, type of event, and TaskCurr.
  2. 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).
  3. 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

  1. At time CURR, task T = (arr, ser) arrives. Push this onto the stack with Tasks.push(T).
  2. 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.)
  3. 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.

  1. Qcust.enqueue(CUST)
  2. If Qcust.getSize() == 1:
  1. If some teller is not busy, let i be the smallest number of a free teller.
  2. Let Ci = Qcust.dequeue(), Ci = (a, s)
  3. 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).
  1. Read a new value for CUST(a, s) from CustArr (if the file is nonempty)
  1. Prepare the next Type 7 arrival event for time a and insert the event into the event list.

My Code:

Event.java

public class Event implements Comparable //, PrintValue { private int time, type;

public Event(int timeE, int typeE) { time = timeE; type = typeE; }

public int getTime() { return time; }

public int getType() { return type; }

public void setTime(int timeE) { time = timeE; }

public void setType(int typeE) { type = typeE; }

public String toString(){ return + time + "," + type; }

// public void printVal() // { // System.out.println("Event: " + "time: " + time + " type: " + type); // }

public int compareTo(Event e) { if( (time < e.getTime()) || ((time == e.getTime()) && (type < e.getType()))) { return -1; } else if((time == e.getTime()) && (type == e.getType())) { return 0; } else { return 1; } } }

Node2.java

//Node2.java

public class Node2 { private T data; private Node2 link;

//constructor public Node2(T newData, Node2 linkValue) { data = newData; link = linkValue; }

public T getData() { return data; }

public Node2 getLink() { return link; }

public void setData(T y) { data = y; }

public void setLink(Node2 linkValue) { link = linkValue; }

}

Olist.java

//OList.java

//Class to implement the Ordered List ADT for generic objects of type T //The type T extends Comparable so that we can use the compareTo() method

public class OList { private Node2 start;//starting node of the list private int size;//size of the list

//constructor public OList() { start = null; size = 0; }

//copy constructor public OList(OList L) { Node2 curr = L.getStart(); T item = curr.getData(); size = L.getSize(); start = new Node2(item, null); //copy the first node Node2 save = start; Node2 newnode = null; for(int i =1; i<=size-1; i++) { curr= curr.getLink();//update the current node to be copied from list L item = curr.getData();//retrieve the data of the current node newnode = new Node2(item,null);//copy the data of the current node //into a new node save.setLink(newnode);//the previous node on the copy list //points to the new node on the copy list save = newnode;//save the new node address for the next cycle } }

public void insert(T y) { Node2 curr=null;; Node2 save=null; Node2 newnode=null;

//search for the correct order position of data value y curr = start;//initialize the search at the beginning of the list while((curr != null) && (curr.getData().compareTo(y)<0)) { //if y comes after the current data, update the search save=curr; curr=curr.getLink(); } newnode = new Node2(y,curr);//new node to hold inserted value if(curr==start) { start = newnode; //insertion at the beginning of the list } else { save.setLink(newnode); //previous node points to the new value } size++; }

public void del(T y) //search for first occurance of value y, and remove { Node2 curr=null; Node2 save=null;

//search for first occurance of y curr = start; while((curr != null) && (curr.getData().compareTo(y) != 0)) { save = curr; curr = curr.getLink(); } if(curr == null) { System.out.println("no deletion: " + y + " not on list"); } else { size--; if(curr == start) { start = curr.getLink();//deletion at the beginning } else { save.setLink(curr.getLink());//delete the current node: //previous node points to following node } } }

public void printListBasic() { Node2 curr = start; System.out.println("list contents: "); while(curr != null) { T out = curr.getData(); System.out.println(out.toString()); curr = curr.getLink(); } System.out.println(" "); }

public void printList() { Node2 curr = start; System.out.println("list contents: "); while(curr != null) { T out = curr.getData(); System.out.println(out); curr = curr.getLink(); } System.out.println(" "); }

public int getSize() { return size; }

public Node2 getStart() { return start; }

public T getData(int i) { Node2 curr = start; for(int j=1; j

}

Stack1gen.java

//Stack1gen.java //array implementation of stack class

public class Stack1gen { int MAX = 30; //maximum number of stack entries

private int top; private T[] stack; //array to hold the stack data

//default constructor public Stack1gen() { top = MAX; //initialize an empty stack stack = (T[]) new Object[MAX]; }

//copy constructor // public Stack1(Stack1 s) // { // top = s.top; // for(int i = top; i<=MAX-1; i++) // { // stack[i] = s.stack[i]; // } // }

public void push(T y) //push data item y onto the stack { assert(top > 0); //check that there is room on the stack top = top -1; stack[top] = y; }

public T pop() //pop the top item from the stack and return it { assert(top < MAX); //check that there is data on the stack T x = stack[top]; top = top +1; return x; }

public int getSize() { return MAX-top; }

public T getTop() { assert(top < MAX); return stack[top]; }

// public void printStack() //print the contents of the stack, from // top to bottom, one item per line, without popping the stack items.

}

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago