Hi!
so i'm trying to make a program with a customer class that keeps how many minutes each customer needs to be served. The driver class CustomerQueue is a queue of all customers that haven't been served yet. Each iteration of the program is one minute, and there is a 25% chance of a new customer entering the queue each minute. Each customer takes 1-5 minutes to be completely served ad removed from queue.
My Code:
import java.util.Queue; import java.util.LinkedList; import java.util.Random; public class CustomerQueue { public static void main(String[] args) { int chance; Queue<Customer> customerQueue = new LinkedList<Customer>(); //Simulating 60 minutes for (int i = 0; i<60; i++) { //25% chance of a new customer, to do this: //get a random number from 1-4, if you get 4, you add a customer Random rand = new Random(); chance = rand.nextInt(4)+1; if(chance == 4) ( Customer newCustomer = new Customer(); customerQueue.add(newCustomer); system.out.println("A new customer just entered the queue.\nTotal number of customers in the Queue is: "+customerQueue.size()); ) //decrease a minute from the firs customer and check if he's fully servieced if(customerQueue(0).timeLeft() == 0) ( customerQueue.remove(); System.out.println("Customer serviced and removed from queue.\nQueue lenght is now: "+customerQueue.size()); ) System.out.println("-------------------one minute elapsed---------------------------"); } } }
import java.util.Random; public class Customer { private int serviceTime; public void customer() { Random rand = new Random(); serviceTime = rand.nextInt(5)+1; } private int timeLeft() { serviceTime =-1; return serviceTime; } }
I'm having a problem adding and removing Customer objects from the queue with these errors:
CustomerQueue.java:22: error: ')' expected
Customer newCustomer = new Customer();
^
CustomerQueue.java:25: error: illegal start of expression
)
^
CustomerQueue.java:30: error: ')' expected
customerQueue.remove();
^
CustomerQueue.java:29: error: not a statement
(
^
CustomerQueue.java:32: error: illegal start of expression
)
^
5 errors