Queues of Items with Processing Time

I need help with this algorithm. I can't figure out the procedures...

A factory has 2 machines of type A and 1 of type B. Items to be processed are put in two Queues, each item has a certain AProcessingTime and BProcessingTime. The items move from the two queues to be processed by the machines of type A first then go to the Queue for machine B. I'm supposed to calculate the total processing time. Here's what I did

public static int totalTime(Queue Q1, Queue Q2)

{

int totalTime = 0;

int totalItems = Q1.size() + Q2.size();

int timeRem = 0;

Queue B = new Queue(totalItems);

while (!(Q1.isEmpty() || Q2.isEmpty()))

{

Item I1 = Q1.dequeue();

Item I2 = Q2.dequeue();

totalTime += I1.AProcessingTime + I2.AProcessingTime;

if (I1.AProcessingTime > I2.AProcessingTime)

{

B.enqueue(I2);

B.enqueue(I1);

}

else

{

B.enqueue(I1);

B.enqueue(I2);

}

timeRem = Math.abs(I1.AProcessingTime - I2.AProcessingTime);

}

Queue Rem = (!Q1.isEmpty()) ? Q1 : ((!Q2.isEmpty()) ? Q2 : null);

if (Rem != null)

{

while (!Rem.isEmpty())

{

Item I = Rem.dequeue();

int APT = I.AProcessingTime;

if (APT > timeRem)

{

timeRem = APT - timeRem;

}

else

{

timeRem = timeRem - APT;

}

B.enqueue(I);

}

totalTime += timeRem;

}

return totalTime;

}

I'm sure I'm still not on the right track. This calculates the total time on the A machines but I'm nowhere near the B machine yet and I dunno how to calculate how much time the Queue of B is empty for example.

[1714 byte] By [norana] at [2007-10-2 4:18:09]
# 1
What is the use of the following statement if you are not using the variable timeRem anywhere in the loop?timeRem = Math.abs(I1.AProcessingTime - I2.AProcessingTime);
Learnablea at 2007-7-15 23:42:14 > top of Java-index,Other Topics,Algorithms...