private void printStatistics() { // add statements into this method! System.out.println("****End of simulation report****"); System.out.println("\t" + " have arrived :" + totalArrival); System.out.println("\t" + " have gone away :" + numGoAway); System.out.println("\t" + " have been served :" + numServed); System.out.println("****Current gaspump info****"); ; gasStationObj.printStatistics(); System.out.println("\tTotal waiting time : " + totalWaitingTime); System.out.println("\tAverage waiting time : " + (totalWaitingTime / numServed)); System.out.println("****Busy Gas Pump info****"); while (!gasStationObj.emptyBusyGasPumpQ()) { GasPump tempgas = gasStationObj.removeBusyGasPumpQ(); tempgas.printStatistics(); } System.out.println("****Free Gas Pump Info****"); while (!gasStationObj.emptyFreeGasPumpQ()) { GasPump tempgas1 = gasStationObj.removeFreeGasPumpQ(); tempgas1.printStatistics(); } // print out simulation results // see the given example in project statement // you need to display all free and busy tellers }
private void doSimulation() { // add statements gasStationObj = new GasStation(numGasPumps, carQLimitation, 1); // Initialize GasStation // Time driver simulation loop for (int currentTime = 0; currentTime < simulationTime; currentTime++) { // Step 1: any new car enters the gas station? getCarData(); // Step 1.1: setup car data if (anyNewArrival) { if (gasStationObj.isCarQTooLong()) { numGoAway++; System.out.println("Car leaves because the queue was too long."); } else { somecar = new Car(carIdCounter, serviceDuration, currentTime); totalArrival++; gasStationObj.insertCarQ(somecar); System.out.println("Car " + totalArrival + " has arrived!"); // Step 1.2: check car waiting queue too long? } } else { System.out.println("\tNo new car!"); } // Step 2: free busy pumps, add to free pumpQ if (!gasStationObj.emptyBusyGasPumpQ()) { if (currentTime >= gasStationObj.getFrontBusyGasPumpQ().getEndIntervalTime()) { if (gasStationObj.numFreeGasPumps() < numGasPumps) { GasPump btp = gasStationObj.removeBusyGasPumpQ(); Car tempcar = btp.switchBusyToFree(); gasStationObj.insertFreeGasPumpQ(btp); } } } // Step 3: get free pumps to serve waiting cars if (gasStationObj.numFreeGasPumps() != 0 && !gasStationObj.emptyCarQ()) { GasPump fp = gasStationObj.removeFreeGasPumpQ(); Car tempscar = gasStationObj.removeCarQ(); gasStationObj.insertBusyGasPumpQ(fp); fp.switchFreeToBusy(tempscar, currentTime); numServed++; } if (anyNewArrival) { carIdCounter++; } if (!gasStationObj.emptyCarQ()) { totalWaitingTime++; } } } // end simulation loop