I managed to update my customer class...but I dont understand how I can increment the waitingTime to every customer that's in the queue, rather than doing it in the customer class? Do I need to write a method in the Queue class so that I can increment it in the waitingQueue class?
public class Customer {
protected int customerNumber;
protected int arrivalTime; //time customer showed up
protected int waitingTime; //in line waiting to be served
protected int transactionTime; //at the counter while being served
protected static int nextNumber = 0;
public static int nextNumber(){
nextNumber++;
return nextNumber;
}
public Customer(){ //default constructor
this.customerNumber = nextNumber();
this.arrivalTime = 0;
this.waitingTime = 0;
this.transactionTime = 0;
}
public static boolean arrived(double arrivalProbability)
//checks to see if a customer has arrived during the passing of one clock unit
{
return (Math.random() < arrivalProbability);
}
public void customerWaiting(){
waitingTime++;
}
public void customerTransaction(int transactionTime){
this.transactionTime = transactionTime;
}
public String placeOrder(){
return "Customer " + customerNumber + " has placed their order.";
}
public String pay(){
return "Customer " + customerNumber + " has paid for their order.";
}
public String depart(){
return "Customer " + customerNumber + " has left.";
}
public String timeArrival(int time){
this.arrivalTime = time;
return "Customer " + customerNumber + " arrived at time unit " + arrivalTime;
}
}
public class WaitingQueue{
protected Queue waitingLine;
public WaitingQueue(){
waitingLine = new Queue(); //intializing waiting queue
}
public void getsInLine(Customer cust){ //when a customer enters, they get put in the waiting line
waitingLine.enqueue(cust);
}
public Customer goesToCounter(){ //when a server is no longer busy, first customer is sent to server
return waitingLine.dequeue();
}
public void passingTime(){ //while all the customers in line are waiting, increment their waitingTime
}
}
public class Queue{
protected class Node{
protected Customer data;
protected Node link;
}
protected int count;
protected Node first;
protected Node last;
public Queue(){
count = 0;
first = null;
last = null;
}
public void enqueue(Customer newCust){
Node oldLast = last;
last = new Node();
last.data = newCust;
last.link = null;
if(count == 0 ){
first = last;
}
else{
oldLast.link = last;
}
count++;
}
public Customer returnData(){
Node temp = new Node();
}
public Customer dequeue(){
Customer temp = first.data;
first = first.link;
count--;
if(count == 0){
last = null;
}
return temp;
}
}
import java.util.Scanner;
public class SimulationDriver{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
//gathering all the information from the user
System.out.print("Please enter simulation time: ");
int simTime = sc.nextInt();
System.out.print("Please enter number of servers: ");
int numOfServers = sc.nextInt();
System.out.print("Please enter transaction time: ");
int transTime = sc.nextInt();
System.out.print("Please enter arrival probability: ");
double arrivalProb = sc.nextDouble();
//setting up customer waiting queue
WaitingQueue waitingLine = new WaitingQueue();
//setting up number of servers in the server list
ServerList servers = new ServerList();
for(int i = 1; i<= simTime; i++){
System.out.println("Clock Unit " + i);
if(Customer.arrived(arrivalProb) == true)){
waitingLine.getsInLine(new Customer());
}
if(){
}
}
System.out.println("Simulation ran for " + simTime + " time units.");
System.out.println("Number of servers: + " numOfServers);
System.out.println("Arrival probability for Customer: " + arrivalProb);
}
}