I am using Blue J
for reference.
What I need to do is after defining 2 constants, MIN = 60 and MAX = 180, which I already did, I am supposed to define the processtime as a random integer between 60 and 240, instead of the constant 120.
Problem is that I am unsure how to do that.
Here is the class, TicketCounter
, in which that is supposed to be implemented in.
public class TicketCounter
{
final static int PROCESS = 120;
final static int MAX_CASHIERS = 10;
final static int NUM_CUSTOMERS = 200;
final static int ARR_TIME = 20;
final static int MIN = 60;
final static int MAX = 180;
public static void main ( String[] args)
{
Customer customer;
LinkedQueue<Customer> customerQueue = new LinkedQueue<Customer>();
int[] cashierTime = new int[MAX_CASHIERS];
int totalTime, averageTime, departs;
System.out.printf("%-25.30s %-30.30s%n", "Number of Cashiers", "Average Time (in seconds)");
/** process the simulation for various number of cashiers */
for (int cashiers=0; cashiers < MAX_CASHIERS; cashiers++)
{
/** set each cashiers time to zero initially*/
for (int count=0; count < cashiers; count++)
cashierTime[count] = 0;
/** load customer queue */
for (int count=1; count <= NUM_CUSTOMERS; count++)
customerQueue.enqueue(new Customer(count*ARR_TIME));
totalTime = 0;
/** process all customers in the queue */
while (!(customerQueue.isEmpty()))
{
for (int count=0; count <= cashiers; count++)
{
if (!(customerQueue.isEmpty()))
{
customer = customerQueue.dequeue();
if (customer.getArrivalTime() > cashierTime[count])
departs = customer.getArrivalTime() + PROCESS;
else
departs = cashierTime[count] + PROCESS;
customer.setDepartureTime (departs);
cashierTime[count] = departs;
totalTime += customer.totalTime();
}
}
}
/** output results for this simulation */
averageTime = totalTime / NUM_CUSTOMERS;
System.out.printf("%10s %30s%n", (cashiers+1), averageTime);
}
}
}
Thank you in advance!
If you have
MIN
andMAX
, and can useRandom
you might do -Which will generate a random value between 60 inclusive and 240 inclusive.
Random.nextInt(int)
which (per the Javadoc),