The group has now been divided, my problem scenario is the following:

There are 2 packing machines, which can pack any type of food, however this needs to be done one at a time. Each food type takes 10 secs to pack.

The packing machines get the food from the processing machines, there are 3 processing machines. The food is stored in queues, the one with the shortest queue, the packing machine will get a food from that queue.

This is my problem:

I have thought about it, I need to add 2 queues to the packing machines because it has to store the food, do I need a queue or is an ArrayList fine?

The thing I dont understand is, how am I going to add the 10 seconds timer (10secs to pack a food).

private int packtime;

I know I need a field like this then I need to define it. Is this right or a static field?

Also how is it going to find which has the shortest queue? the .size method right? However, once this is done how will it just pick a food from the processing queue and add it to the packing machine queue/arraylist. One it is added, then somehow it will tell the packing machine and the processing machine queue will go down by1.

I am a beginner in java, so if I have made a lot of mistakes, please understand.

I have thought about it, I need to add 2 queues to the packing >>machines because it has to store the food, do I need a queue or is an ArrayList fine?

Use Java's Queue class. An ArrayList is not the same thing as a queue; a queue is a special type of list where the first item added to the list is the first item taken out of the list. So you could use an ArrayList, but you would have to make sure to remember which item's turn it was. Instead, make life easy - use Queue.

The thing I dont understand is, how am I going to add the 10 seconds timer (10secs to pack a food).

Thread.getCurrentThread().sleep(10000);

Also how is it going to find which has the shortest queue? the .size method right?

Yes.

However, once this is done how will it just pick a food from the processing queue and add it to the packing machine queue/arraylist. One it is added, then somehow it will tell the packing machine and the processing machine queue will go down by1.

Use the Queue class methods. In particular, the remove() method removes the next item and returns it. So you could do something like this:

//Up here you declare your Queue Objects..
//Find the smallest list .. 

packingMachineQueue.offer( processingMachineQueue.remove() );

I am a beginner in java, so if I have made a lot of mistakes, please understand.

Edited 3 Years Ago by pritaeas: Fixed formatting

Thread.getCurrentThread().sleep(10000);


I dont understand how the above works, I know it takes 10 secs off but how is it actually doing that? Can you provide an example in a small method. Thanks

Edited 6 Years Ago by ben1: n/a

It gets the current thread of execution then tells that thread to sleep for 10000 milliseconds which is 10 seconds. Beyond that I don't know the details, why don't you look into it and let us know what you find.

I checkd the internet and like u said it just makes the current thread go to sleep for 10secs.

I want to buy a java book which will help me with loops, arrays, arraylists, hashmaps, scanners etc....as a lot of you know a lot about java can you recommend me a good java book which is easy to understand...

is Java All-in-one Desk Reference for Dummies a good book?

Edited 6 Years Ago by ben1: n/a

This article has been dead for over six months. Start a new discussion instead.