-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
255 lines (143 loc) · 5.01 KB
/
Copy pathPerson.java
File metadata and controls
255 lines (143 loc) · 5.01 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
package ethicalengine;
/*
* The Classes inheriting from Character.java :
* 1. Person.java .
* 2, Animal.java .
*
*
* */
public class Person extends Character {
private String charactertype ;
private Profession profession ;
public boolean isrepresentive ;
private boolean isPregnant = false ;
private boolean isYou = false;
AgeCategory agecategory ;
private String agegroup ;
public Person (int age, Gender gender, BodyType bodytype){
super.setAge(age) ;
this.profession = profession ;
super.setGender(gender);
super.setBodyType(bodytype);
}
public Person(){
}
//Person [ ] personArray = new Person[7] ;
public Person (int age, Profession profession, Gender gender, BodyType bodytype, boolean isPregnant){
super.setAge(age) ;
this.profession = profession ;
super.setGender(gender);
super.setBodyType(bodytype);
this.setPregnant(isPregnant) ;
}
public Person (int age, Profession profession, Gender gender, BodyType bodytype){
super.setAge(age) ;
this.profession = profession ;
super.setGender(gender);
super.setBodyType(bodytype);
}
// Copy Constructor in Java
/*
* A Copy constructor in Java is a constructor that creates an object using another object of the same Java Class.
* That is helpful when we want to copy a complex object that has several fields, or when we want to make a deep copy
* of an existing object.
* */
public Person (Person otherPerson){
this.charactertype = otherPerson.charactertype ;
this.profession = otherPerson.profession ;
super.setAge( otherPerson.getAge() );
this.gender = otherPerson.gender ;
this.isrepresentive = otherPerson.isrepresentive ;
super.setBodyType( otherPerson.getBodyType() );
this.setPregnant( otherPerson.isPregnant );
this.setAsYou(otherPerson.isYou) ;
}
// Enum for age category.
public enum AgeCategory {
BABY, CHILD, ADULT, SENIOR ;
}
// Only ADULTs have professions, other age categories should return the default value NONE.
// Additionally, you are tasked with coming up with at least two more categories you deem feasible.
//
public enum Profession {
DOCTOR,CEO,CRIMINAL,HOMELESS,UNEMPLOYED, UNKNOWN, NONE ;
}
/*getAgeCategory() - returns an enumeration value of the type AgeCategory depending
* on the persons age with one of the following values .
* */
public AgeCategory getAgeCategory() {
if (0 <= super.getAge() && super.getAge() <= 4) {
return AgeCategory.BABY ;
}
else if ( 4 < super.getAge() && super.getAge() <= 16 ) {
return AgeCategory.CHILD ;
}
else if (16 < super.getAge() && super.getAge() <= 68) {
return AgeCategory.ADULT ;
}
else {
return AgeCategory.SENIOR ;
}
}
// getProfession returns an enumeration value of type Profession, which must include the values as above.
// Only ADULTs would have professions , other age categories should return the default value UNKNOWN .
//
public Profession getProfession ( ) {
if ( this.getAgeCategory() != AgeCategory.ADULT ) {
return Profession.NONE ;
}
else
return this.profession;
}
// returns a boolean indicating whether the person is pregnant.
// For all instances of Person whose gender is not FEMALE this should return false.
private boolean checkPregnant ( ) {
if (getGender() == Gender.FEMALE && getAgeCategory() == AgeCategory.ADULT) {
return true ;
}
else
return false;
}
public boolean isPregnant()
{
return this.isPregnant;
}
// sets the value returned by isPregnant() while preventing invalid states, such as a pregnant male.
public void setPregnant (boolean pregnant) {
if (checkPregnant()) {
this.isPregnant = pregnant ;
}
else
this.isPregnant = false;
}
// Returns a boolean indicating whether a person is a representative of the user eg : you are one of the passengers in the car.
public void setAsYou (boolean isYou) {
this.isYou = isYou ;
}
// isYou(): returns a boolean indicating whether the person is representative of the user,
// e.g., you are one of the passengers in the car.
public boolean isYou() {
return this.isYou ;
}
public String toString() {
String rtnStr = "";
if(isYou()) {
rtnStr += "you ";
}
rtnStr += super.getBodyType()+" ";
rtnStr += this.getAgeCategory()+" ";
if (getProfession() != Profession.NONE) {
rtnStr += getProfession()+" ";
}
rtnStr += super.getGender()+" ";
if (isPregnant()) {
rtnStr += "pregnant";
}
return rtnStr.toLowerCase();
}
/* public static Person gettheRandomPerson() {
// TODO Auto-generated method stub
return null;
}
*/
}