The program I am working on is a simulation for wait times in a line. I need the
ID: 3631301 • Letter: T
Question
The program I am working on is a simulation for wait times in a line.
I need the empty methods in classes:
**
Customer
Server
WaitingCustomerQueue
**
finished and the MainProgram finished.
This needs to be implemented as well:
Use the following Arrival Probability Model where Arrival Probability is .65 for one Clock Unit .
public static boolean isCustomerArrived(double arrivalProbability)
{
return Math.random() < arrivalProbability;
}
Use Average Transaction Time: 4.
Run for 30 clock units.
The rest *should* be working.
Sample Run should look like this:
Customer number 1 arrived at time unit 6
Customer number 2 arrived at time unit 7
Server No: 1 Customer number 1 departed at clock unit 11
Customer number 3 arrived at time unit 13
Customer number 4 arrived at time unit 15
Server No: 1 Customer number 2 departed at clock unit 16
etc:
Simulation ran for 100 time units
Number of servers: 1
Average transaction time: 5
Average arrival time difference between customers: 4
Total wait time: 174
Number of customers who completed a transaction: 17
Number of customers left in the servers: 1
Number of customers left in the queue: 5
Average wait time: 7.57
My code is posted on pastebin: http://pastebin.com/k1XMXkGT
Explanation / Answer
class ListNode
{
// package access (not public, private, or protected)
// List can access these directly
Object data;
ListNode nextNode;
// constructor creates a ListNode that refers to object
ListNode( Object object )
{
this( object, null );
}
// constructor creates ListNode that refers to
// Object and to next ListNode
ListNode( Object object, ListNode node )
{
data = object;
nextNode = node;
}
return reference to data in node
Object getObject()
{
return data; // return Object in this node
}
// return reference to next node in list
ListNode getNext()
{
return nextNode;
}
}
package com.deitel.jhtp6.ch17;
public class List {
private ListNode firstNode;
private ListNode lastNode;
private String name;
// list “name” used in printing
// constructor: empty list with no name
public List()
// constructor: empty List with a name
public List( String listName )
// insert Object at front of List
public void insertAtFront( Object insertItem )
// insert Object at end of List
public void insertAtBack( Object insertItem )
// remove first node from List; throw exception if empty list
public Object removeFromFront() throws EmptyListException
// remove last node from List; throw exception if empty list
public Object removeFromBack() throws EmptyListException
// determine whether list is empty
public boolean isEmpty()
// output List contents
public void print()
// Class Queue.
package com.deitel.jhtp6.ch17;
public class Queue
{
private List queueList;
// no-argument constructor
public Queue()
{
queueList = new List( "queue" );
} // end Queue no-argument constructor
// add object to queue
public void enqueue( Object object )
{
queueList.insertAtBack( object );
}
// remove object from queue
public Object dequeue() throws EmptyListException
{
return queueList.removeFromFront();
}
// determine if queue is empty
public boolean isEmpty()
{
return queueList.isEmpty();
}
// output queue contents
public void print()
{
queueList.print();
}
} private static int numCustomers;
private int queueEntryTime;
private int waitTime; // elapsed time in queue
private int serviceEntryTime;
private int serviceTime; // elapsed time in service
public Customer(int clock)
public void enterQueue(int clock)
public int getQueueEntryTime()
public void exitQueue(int clock)
private int elapsedTime(int begin, int end) throws CustomerDataException
public int getWaitTime()
public int getServiceTime()
public void enterService(int clock) throws CustomerDataException
public int getServiceEntryTime()
public void exitService(int clock)
public String toString()
package com.deitel.jhtp6.ch17;
public class CustomerDataException extends RuntimeException
{
public CustomerDataException(String customerData)
{
super("Customer data inconsistent: " + customerData);
}
}private static int nextArrivalTime;
private static int nextServiceCompleteTime;
private static int clock; // current simulation time
private static Random customerGenerator;
private static Random serviceGenerator;
private static boolean serviceBusy = false;
Queue checkoutQueue = new Queue();
Customer customerBeingServed; // ? Correction 3/28/07
List customers = new List("Customers Served");
customerGenerator = new Random();
serviceGenerator = new Random();
clock = 0;
updateNextArrivalTime();
clock = nextArrivalTime; // simulation begins with first customer arrival
Customer c1 = new Customer(clock); // construct first customer
c1.enterQueue(clock);
c1.exitQueue(clock);
customerBeingServed = c1; // ? Correction 3/28/07
customerBeingServed.enterService(clock); // customer added to service
serviceBusy = true;
updateNextServiceTime();
updateNextArrivalTime();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.