-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerQueue.java
More file actions
96 lines (86 loc) · 2.28 KB
/
CustomerQueue.java
File metadata and controls
96 lines (86 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/***
* @author Carson Stotler
* @version 0.1
* Date of Creation: Oct. 13, 2022
* Last Date Modified: Oct. 18, 2022
* Assignment: HW 4
* Simulating a movie theater line with customers and servers
*/
import java.util.Queue;
// import java.util.Iterator;
import java.util.LinkedList;
public class CustomerQueue{
//data members
private Queue<Customer> customers;
/***
* no-arg Constuctor
* no paramateres
* Initializes customers Queue as a new LinkedList<Customer>
*/
public CustomerQueue(){
this.customers = new LinkedList<Customer>();
}
/***
* Method to return next Customer by using poll from queue
* no param
* @return Customer represents Customer on top of queue
*/
public Customer getNextCustomer(){
return customers.poll();
}
/***
* void method to update waiting time for each customer still in queue - using incrementWaitingTime
* no param
* no return
*/
public void updateWaitingTime(){
for ( Customer c: customers ){
c.incrementWaitingTime();
}
}
/***
* Method to return next Customer's waiting time - using peek
* no param
* @return int of waiting time of next customer
*/
public int totalWaitingTime(){
return customers.peek().getWaitingTime();
}
/***
* void method to add a customer to customers by using offer
* @param c a Customer representing the new Customer being added
* no return
*/
public void addCustomer(Customer c){
customers.offer(c);
}
/***
* Method to check if customers is empty by checking size
* no param
* @return boolean -- true if customers is empty, false if not
*/
public boolean isEmpty(){
return (size() == 0);
}
/***
* method to return size of customers, by using Queue's size method
* no param
* @return int customers.size();
*/
public int size(){
return customers.size();
}
/***
* Method toString to return a formatted String of CustomerQueue information
* no parameters
* @return String of formatted CustomerQueue information
*/
@Override
public String toString(){
String out = "";
for ( Customer c : customers ){
out += c.toString() + "\n";
}
return out;
}
}