So I have to implement a checkout line using a priority queue. I'm really stuck. I have 3 classes, a Register class, Store class, and customer class.
Each customer has a service time which is the time it takes to check out.
There are ten registers.
Reach register has a line.
I have to add a customer based on which line has the lowest total service time.
I need help on how to get the total service time for a line of a register.
Here are my three classes so far:
Store:
import java.util.LinkedList;
import java.util.PriorityQueue;
public class Store {
private PriorityQueue<Register> regs;
public Store(){
this.regs = new PriorityQueue<Register>();
for(int i = 0;i<=10; i++){
regs.add(new Register());
}
}
private Register leastFullRegister() {
double minWaitTime = Double.MAX_VALUE;
Register leastFullRegister = null;
for ( Register r : regs ) {
if ( r.getTotalEnqueue() < minWaitTime ) {
minWaitTime = r.getTotalEnqueue();
leastFullRegister = r;
}
}
return leastFullRegister;
}
}
Register:
import java.util.PriorityQueue;
public class Register implements Comparable<Register> {
private boolean open; // line open or not?
private PriorityQueue<Customer> line; //the line of customers
private int waitTime;
Register(){
open = false;
waitTime = 0;
this.line = new PriorityQueue<Customer>();
}
public double getTotalEnqueue(){
double totalTime = 0;
//go through every customer and get the serviceTimes and add them up
//This is to see which line is shorter
return totalTime;
}
public void addCustomer(Customer c){
line.add(c);
}
public Customer pollCustomer(){
return line.poll();
}
public boolean isOpen(){
// some how open and close lines?
return true;
}
@Override
public int compareTo(Register reg) {
return 0;
}
}
Customer
public class Customer {
private double serviceTime;
private int count;
Customer(){
serviceTime = Math.random() + 2;
count = 0;
}
public double getServiceTime(){
serviceTime = Math.random() + 2;
count++;
return serviceTime;
}
public int getCount(){
return count;
}
}