A method has been written that increments time in minutes that simulates how much time it takes to process item in a supermarket queue and if there is an empty queue, skip it and loops around to find the number of items processed in each interval (each time a minute has passed). I was wondering if there are ways to improve the code I have written??
private Queue[] lines;
private double time; // Time measured in minutes
private static double item_per_min;
private static double time_inc;
private static Random rand = new Random();
static int x = 0;
public static final double lambda = item_per_min * time_inc;
public static double target_Probability = rand.nextDouble();
public static final double target_ProbabilityabilityOfX = Math.pow(lambda, x) * Math.exp(-lambda) / factorial(x); // Poisson
// distribution
public void add_time(double time_inc)
{
for (int i = 0; i < lines.length; i++) // Loops
{
if (lines[i].empty())
{
continue;
}
while (true)
{
time += time_inc;
if (target_ProbabilityabilityOfX > target_Probability)
{
break;
}
x++;
target_Probability -= target_ProbabilityabilityOfX;
}
while (!lines[i].empty() && x > 0)
{
lines[i].decrement();
x--;
}
}
this.display();
}