feat: update ServiceCounter and ShopSimulation
This commit is contained in:
committed by
Yadunand Prem
parent
6f4af3ba97
commit
46f0ad140f
@@ -5,11 +5,12 @@
|
|||||||
* @author Yadunand Prem
|
* @author Yadunand Prem
|
||||||
* @version CS2030S AY22/23 Semester 2
|
* @version CS2030S AY22/23 Semester 2
|
||||||
*/
|
*/
|
||||||
public class ServiceCounter {
|
public class ServiceCounter implements Comparable<ServiceCounter> {
|
||||||
private static int lastId;
|
private static int lastId;
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private boolean available;
|
private boolean available;
|
||||||
|
private Queue<Customer> queue;
|
||||||
|
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return available;
|
return available;
|
||||||
@@ -23,9 +24,10 @@ public class ServiceCounter {
|
|||||||
this.available = true;
|
this.available = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceCounter() {
|
public ServiceCounter(int queueSize) {
|
||||||
this.id = lastId++;
|
this.id = lastId++;
|
||||||
this.available = true;
|
this.available = true;
|
||||||
|
this.queue = new Queue<Customer>(queueSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,4 +35,14 @@ public class ServiceCounter {
|
|||||||
return "S" + id;
|
return "S" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ServiceCounter o) {
|
||||||
|
if (this.queue.length() < o.queue.length()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (this.id < o.id) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
Shop.java
10
Shop.java
@@ -9,13 +9,13 @@ public class Shop {
|
|||||||
private ServiceCounter[] counters;
|
private ServiceCounter[] counters;
|
||||||
private Queue queue;
|
private Queue queue;
|
||||||
|
|
||||||
public Shop(int numOfCounters, int queueSize) {
|
public Shop(int numOfCounters, int shopQueueSize, int counterQueueSize) {
|
||||||
this.counters = new ServiceCounter[numOfCounters];
|
this.counters = new ServiceCounter[numOfCounters];
|
||||||
for (int i = 0; i < numOfCounters; i++) {
|
for (int i = 0; i < numOfCounters; i++) {
|
||||||
this.counters[i] = new ServiceCounter();
|
this.counters[i] = new ServiceCounter(counterQueueSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queue = new Queue(queueSize);
|
this.queue = new Queue(shopQueueSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,10 +34,6 @@ public class Shop {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Queue getQueue() {
|
|
||||||
return this.queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isQueueFull() {
|
public boolean isQueueFull() {
|
||||||
return this.queue.isFull();
|
return this.queue.isFull();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ class ShopSimulation extends Simulation {
|
|||||||
public ShopSimulation(Scanner sc) {
|
public ShopSimulation(Scanner sc) {
|
||||||
initEvents = new Event[sc.nextInt()];
|
initEvents = new Event[sc.nextInt()];
|
||||||
int numOfCounters = sc.nextInt();
|
int numOfCounters = sc.nextInt();
|
||||||
int maxQueueSize = sc.nextInt();
|
int maxCounterQueueSize = sc.nextInt();
|
||||||
|
int maxShopQueueSize = sc.nextInt();
|
||||||
|
|
||||||
Shop shop = new Shop(numOfCounters, maxQueueSize);
|
Shop shop = new Shop(numOfCounters, maxShopQueueSize, maxCounterQueueSize);
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
while (sc.hasNextDouble()) {
|
while (sc.hasNextDouble()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user