forked from MissMeriel/ShoppingCenterSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
141 lines (127 loc) · 2.83 KB
/
Customer.java
File metadata and controls
141 lines (127 loc) · 2.83 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package master1;
/**
* This class is used to represent a customer shopping in a Shopping Center
*
* @author Jon Spratt, Meriel Stein
* @version v1_11.20.2016
*/
public class Customer extends KeyedItem<String>{
/**
* The name of this customer
*/
private String name;
/**
* Number of items in this customer's shopping cart
*/
private int cart;
/**
* Minutes this customer has spent shopping
*/
private int shoppingTime;
/**
* true if this Customer is currently in a CheckoutLine
*/
private boolean inCheckout;
/**
* Default constructor for an anonymous customer
*/
public Customer() {
super("N/A");
name = "N/A";
cart = 0;
shoppingTime = 0;
inCheckout = false;
}
/**
* Constructor for a named customer
* @param name customer's name
*/
public Customer(String name) {
super(name);
this.name = name;
cart = 0;
shoppingTime = 0;
inCheckout = false;
}
/**
* Standard Accessor - for the name of this customer
*
* @return customer's name
*/
public String getName() {
return name;
}
/**
* Standard Accessor - for the shopping cart of this customer
*
* @return number of items in this customer's shopping cart
*/
public int getCart() {
return cart;
}
/**
* Standard Accessor - for the amount of time this customer has spent
* shopping
*
* @return minutes this customer spent shopping
*/
public int getShoppingTime() {
return shoppingTime;
}
/**
* Reset time spent shopping to zero
*/
public void resetShoppingTime() {
shoppingTime = 0;
}
/**
* Updates inCheckout to true
*/
public void enterCheckout() {
inCheckout = true;
}
/**
* Updates inCheckout to false
*/
public void leaveCheckout() {
inCheckout = false;
}
/**
* Add an item to the customer's cart
*/
protected void addItemToCart() {
cart++;
}
/**
* Remove an item from the customer's cart
*/
protected void removeItemFromCart() {
if (cart == 0) {
throw new CartException("The cart is empty.");
}
else {
cart--;
}
}
/**
* Increase the amount of time the customer has been shopping by one.
*/
protected void incrementShoppingTime() {
shoppingTime++;
}
/**
* format when inCheckout: Customer Eevee has 7 items in the shopping basket.
* format when !inCheckout: Customer Pansage with 2 items present for 27 minutes.
* may be able to resolve this difference with functional programming so we
* can get rid of maintenance cost of inCheckout
*/
public String toString() {
if (inCheckout) {
return "\tCustomer " + name + " has " + cart
+ " items in the shopping basket.\n";
} else {
return "\tCustomer " + name + " with " + cart + " items present for "
+ shoppingTime + " minutes.\n";
}
}
}