-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer.java
248 lines (201 loc) · 6.48 KB
/
Customer.java
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Customer {
private String fName;
private String lName;
private String address1;
private String address2;
private String city;
private String state;
private int zipcode;
private String email;
private String username;
private String password;
private double accountBalance;
private HashMap<String, Double> transactionHistory = new HashMap<String, Double>();
public void addTransaction(String bridgeName, Double amountCharged) {
transactionHistory.put(bridgeName, amountCharged);
System.out.println("You crossed " + bridgeName + ". The toll charged to your account is $" + amountCharged);
}
public void getHistory() {
Set set = transactionHistory.entrySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Map.Entry mentry = (Map.Entry) iterator.next();
System.out.print("Bridge Crossed: " + mentry.getKey() + " & Amount Charged: $");
System.out.println(mentry.getValue());
}
}
public double getAccountBalance() {
return this.accountBalance;
}
public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}
public void addFunds(double amount) {
setAccountBalance(accountBalance + amount);
}
public void subtractFunds(double amount) {
setAccountBalance(accountBalance - amount);
}
private Payment creditCard;
private Vehicle car;
Customer(String fName, String lName, String address1, String address2, String city, String state, int zipcode,
String email, String username, String password, Payment creditCard, Vehicle car) {
setfName(fName);
setlName(lName);
setAddress1(address1);
setAddress2(address2);
setCity(city);
setState(state);
setZipcode(zipcode);
setEmail(email);
setUsername(username);
setPassword(password);
setCreditCard(creditCard);
setCar(car);
setAccountBalance(0);
}
public void updateAddress(String address1, String address2, String city, String state, int zipcode) {
setAddress1(address1);
setAddress2(address2);
setCity(city);
setState(state);
setZipcode(zipcode);
}
public void updatePassword(String password) {
setPassword(password);
}
public void updateCard(String cardName, String cardNum, String expDate, String ccv) {
this.creditCard = new Payment(cardName, cardNum, expDate, ccv);
}
public void updateCar(String make, String model, String color, int year, String lPlate) {
this.car = new Vehicle(make, model, color, year, lPlate);
}
public Vehicle getCar() {
return this.car;
}
public void setCar(Vehicle car) {
this.car = car;
}
public Payment getCreditCard() {
return creditCard;
}
public void setCreditCard(Payment creditCard) {
this.creditCard = creditCard;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
if (validPassword(password)) {
this.password = password;
} else {
this.password = "";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
if (validUsername(username)) {
this.username = username;
} else {
this.username = "";
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getZipcode() {
return zipcode;
}
public void setZipcode(int zipcode) {
this.zipcode = zipcode;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
// Checking the input string meets eligibility requirements to be a username
public boolean validUsername(String username) {
if (username.matches("[a-z0-9]+") && username.length() >= 6) {
return true;
}
return false;
}
// Checking the input string meets eligibility requirements to be a password
public boolean validPassword(String password) {
if (password.length() >= 8 && password.matches("[a-zA-Z0-9]+@") || password.matches("[a-zA-Z0-9]+!")) {
return true;
}
return false;
}
// Check if username already exists in a "database" (dictionary)
public boolean duplicateUsername(String username, Dictionary<String, String> dictionary) {
Enumeration<String> e = dictionary.keys();
while (e.hasMoreElements()) {
if (e.nextElement().equals(username)) {
return true;
}
}
return false;
}
// Prints customer info
public void getAccountInfo() {
System.out.println("-- Customer Info -- ");
System.out.println("First name: " + this.fName);
System.out.println("Last name: " + this.lName);
System.out.println("Address 1: " + this.address1);
System.out.println("Address 2: " + this.address2);
System.out.println("Zipcode: " + this.zipcode);
System.out.println("State: " + this.state);
System.out.println("Email: " + this.email);
System.out.println("Password: " + this.password);
}
public void getCardInfo() {
System.out.println("-- Credit Card Info -- \n" + this.creditCard.getInfo());
}
public void getCarInfo() {
System.out.println("-- Vehicle Info -- \n" + this.car.getInfo());
}
}