-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMember.java
More file actions
148 lines (124 loc) · 3.02 KB
/
Member.java
File metadata and controls
148 lines (124 loc) · 3.02 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
package code;
import java.util.ArrayList;
public class Member {
private static int numMembers = 0;
private int id;
private String name;
private String phoneNumber;
private Address address;
private int availableSeats;
private boolean isAvailable;
private int numChildren;
private boolean absent = false;
private boolean hasCar;
private ArrayList<Cost2> costs;
public Member() {
costs = new ArrayList<>();
}
public Member(String name, String phoneNumber, Address addr,
int availableSeats, int numChildren, boolean hasCar) {
numMembers++;
id = numMembers;
this.name = name;
this.phoneNumber = phoneNumber;
this.address = addr;
this.availableSeats = availableSeats;
this.isAvailable = true;
this.numChildren = numChildren;
this.hasCar = hasCar;
this.absent = false;
costs = new ArrayList<>();
}
public static int getNumMembers() {
return numMembers;
}
public int getID() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public void addChildToNumChildren(int numChildren) {
if(numChildren < 0) {
throw new IllegalArgumentException();
}
this.numChildren += numChildren;
}
public void removeChildrenFromNumChildren(int numChildren) {
if(numChildren < 0 || numChildren > this.numChildren) {
throw new IllegalArgumentException("Invalid number of children being removed.");
}
this.numChildren -= numChildren;
}
public String getName() {
return this.name;
}
public boolean getHasCar() {
return this.hasCar;
}
public void setNumChildren(int numChildren) {
this.numChildren = numChildren;
}
public int getNumChildren() {
return this.numChildren;
}
public ArrayList<Cost2> getAllCosts() {
//copy cost object to return
//Cost costCopy = new Cost(cost);
//return costCopy;
return costs;
}
public Cost2 getCostByID(int id) {
for(int i = 0; i < costs.size(); i++) {
if(id == costs.get(i).getCostID()) {
return costs.get(i);
}
}
return null;
}
public void addCost(Cost2 cost) {
costs.add(cost);
}
public double getCostTotal() {
double total = 0;
if(costs == null) {
return 0;
}
else {
for(int ctr = 0; ctr < costs.size(); ctr++) {
total += costs.get(ctr).getCost();
}
return total;
}
}
public boolean isAbsent() {
//have a method that lets u set a child to be absent - child arraylist?
return absent;
}
public void deleteOneFromNumMembers() {
numMembers--;
}
public void resetCost() {
if(!costs.isEmpty()) {
costs.removeAll(costs);
Cost2.resetCostCounter();
}
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append(name);
str.append("\n\tPhone #: ");
str.append(phoneNumber + "\n\t");
str.append(address);
str.append("\n\tHas car: " + (hasCar ? "Yes" : "No"));
str.append("\n\tNumber of Children: " + numChildren);
if(costs != null) {
for(int ii = 0; ii < costs.size(); ii++) {
str.append("\n\tCosts " + (ii + 1) + ": " + costs.get(ii));
str.append("\n");
}
}
return str.toString();
}
}