-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistry.java
More file actions
262 lines (230 loc) · 7.3 KB
/
Copy pathRegistry.java
File metadata and controls
262 lines (230 loc) · 7.3 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import java.util.ArrayList;
/**
* Registry class
*
* @author jusps
* @version 1
*/
public class Registry {
private ArrayList<Customer> registryList = new ArrayList<Customer>();
/**
* gets the number of members in registryList
*
* @return number of members in registryList
*/
public int numMem() {
//failsafe if empty
if (registryList.isEmpty()) return 0;
//return the size of the ArrayList
return registryList.size();
}
/**
* gets the number of members that aren't registered with a premium membership
*
* @return number of regular members
*/
public int numRegMem() {
//failsafe if empty
if (registryList.isEmpty()) return 0;
//count up for each member that is not premium
int total = 0;
for (Customer custom : registryList) {
if (!custom.isPremium()) total++;
}
//return the total
return total;
}
/**
* gets the number of members registered for a premium membership
*
* @return number of premium members
*/
public int numPremMem() {
//failsafe if empty
if (registryList.isEmpty()) return 0;
//count up for each member that is premium
int total = 0;
for (Customer custom : registryList) {
if (custom.isPremium()) total++;
}
//return the total
return total;
}
/**
* gets an array of the names of the members
*
* @return array of Strings
*/
public String[] nameMem() {
//failsafe if empty
if (registryList.isEmpty()) return new String[] {"",""};
//make array of names from registry list
String[] result = new String[registryList.size()];
//set to names
for (int i=0;i<result.length;i++) result[i] = registryList.get(i).getName();
//return array of names
return result;
}
/**
* gets the age at a particular index in the registryList
*
* @param int index
* @return int age at index in registryList
*/
public int getAge(int index) {
return registryList.get(index).getAge();
}
/**
* gets the paymentType at a particular index in the registryList
*
* @param int index
* @return String paymentType at index in registryList
*/
public String getPaymentType(int index) {
return registryList.get(index).getPayMethod();
}
/**
* gets the premium status at a particular index in the registryList
*
* @param int index
* @return boolean premium status at index in registryList
*/
public boolean[] isPremium(int index) {
//isPremium[0] is whether premium, isPremium[1] is if paid
return registryList.get(index).getPremiumStatus();
}
/**
* gets the moneySpent at a particular index in the registryList
*
* @param int index
* @return double moneySpent at index in registryList
*/
public double getMoneySpent(int index) {
return registryList.get(index).getMoneySpent();
}
/**
* gets the address at a particular index in the registryList
*
* @param int index
* @return String address at index in registryList
*/
public String getAddress(int index) {
return registryList.get(index).getAddress();
}
/**
* gets the private payment details at a particular index in the registryList
*
* @param int index
* @return String of private payment details at index in registryList
*/
public String getPrivateDetails(int index) {
return registryList.get(index).getInfo();
}
/**
* adds member to registryList
*
* @param String name
* @param String payMethod
* @param int age
* @param boolean isPremium
* @param boolean isPaidPremium
* @param String address
* @param String info
*/
public void addMember(String name, String payMethod, int age, boolean isPremium, boolean isPaidPremium, String address, String info) {
//failsafe if empty
if (registryList.isEmpty())
registryList.add(new Customer(name, payMethod, age, new boolean[] {isPremium, isPaidPremium}, address, info));
else {
//find where to alphabetically place this
int index = 0;
while (index < registryList.size() && registryList.get(index).getName().compareTo(name) < 0) index++;
registryList.add(index, new Customer(name, payMethod, age, new boolean[] {isPremium, isPaidPremium}, address, info));
}
}
/**
* changes name of the account of the customer at index
*
* @param int index
* @param String name
*/
public void changeName(int index, String name) {
registryList.get(index).changeName(name);
}
/**
* changes the payment type of the customer at index in the registryList
*
* @param int index
* @param String type
*/
public void changePaymentType(int index, String type) {
registryList.get(index).setPayMethod(type);
}
/**
* sets the member at index to premium membership status provided
*
* @param int index
* @param bool isPremium
* @param bool hasPaidThisMonth
*/
public void setPremMem(int index, boolean isPremium, boolean hasPaidThisMonth) {
//set whether premium
registryList.get(index).setPremium(isPremium);
//if premium, set if paid this month
if (isPremium) registryList.get(index).setPaidThisMonth(hasPaidThisMonth);
}
/**
* lowers all membership status, used at the start of a new month
* paid members become unpaid members, and unpaid members become regular customers
*
*/
public void lowerMembershipStatus() {
//use a for loop to go over every customer
for (Customer customer : registryList) {
//get the current status of each customer
boolean[] status = customer.getPremiumStatus();
//status[0] is if premium, status[1] is if paid this month
if (status[0]) {
if (status[1]) {
customer.setPaidThisMonth(false);
} else customer.setPremium(false);
}
}
}
/**
* adds money spent to the account of the customer at index
*
* @param int index
* @param double money
*/
public void addMoneySpent(int index, double money) {
registryList.get(index).addMoneySpent(money);
}
/**
* changes the age on file of the current customer
*
* @param int index
* @param int age
*/
public void changeAge(int index, int age) {
registryList.get(index).setAge(age);
}
/**
* changes the address on file of the current customer
*
* @param int index
* @param String address
*/
public void changeAddress(int index, String address) {
registryList.get(index).setAddress(address);
}
/**
* changes the additional payment information on file of the current customer
*
* @param int index
* @param String additionalInfo
*/
public void changeInfo(int index, String additionalInfo) {
registryList.get(index).setInfo(additionalInfo);
}
}