Hello, for my assignment for my java I need to basically represent a supermarket checkout, with customers using a linkedlist queue
Each customer has a certain amount of groceries (randomized between 1-10)
When they are at the end of the queue they are getting served, I took each grocery as taking 1 second, so if a customer had 7 groceries and was at the top of the queue, after 7 seconds they will be removed from the queue, then the new top customer in the queue gets 'served'
I can get my timerTask working etc, however I can't work out how to once the TimerTask has ended (customer has finished) to return something so that I can remove it from the queue and start the next one.
Here's the code for my Timer/Task
Code
import java.util.Timer;
import java.util.TimerTask;
public class Schedule
{
private Timer timer;
private String customerName;
public Schedule(Customer customer) {
timer = new Timer();
timer.schedule(new ScheduleTask(), customer.getgroceries()*1000);
customerName = customer.getcustomer();
}
class ScheduleTask extends TimerTask {
@Override
public void run()
{
System.out.format(customerName + " Finished\n");
timer.cancel(); //Terminate the timer thread
}
}
}
I have seperate methods for Customer and CustomerQueue
When testing it I do
Code
Customer customer1 = new Customer();
Customer customer2 = new Customer();
Customer customer3 = new Customer();
Schedule schedule1 = new Schedule(customer1);
Schedule schedule2 = new Schedule(customer2);
Schedule schedule3 = new Schedule(customer3);
But then all the Customers start at the same time instead of customer 1 waiting for customer 2 to finish

I hope you understand what I need!