Repository navigation
Expand file tree
/
Copy pathPerson.java
More file actions
184 lines (154 loc) · 4.69 KB
/
Copy pathPerson.java
File metadata and controls
184 lines (154 loc) · 4.69 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
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
/**
* Person
*
* @author mostafa ahmadi(9701923)
*/
public class Person {
private String fName;
private String lName;
private Integer nationalId;
private String birthPlace;
private String birthDate;
private String spuseName;
private Gender gender;/*male or female */
private Status status;/*alive or dead */
private LinkedList<Person> children; /*This list represents each person's children and can be null*/
private Person spouse;
private Person parent;
/** no arg constructor */
public Person(){
}
/** constructor */
public Person(String fName , String lName , Integer nationalId , String birthPlace){
this.fName = fName;
this.lName = lName;
this.nationalId = nationalId;
this.birthPlace = birthPlace;
}
public String getFName() {
return this.fName;
}
public void setFName(String fName) {
this.fName = fName;
}
public String getLName() {
return this.lName;
}
public void setLName(String lName) {
this.lName = lName;
}
public Integer getNationalId() {
return this.nationalId;
}
public void setNationalId(Integer nationalId) {
this.nationalId = nationalId;
}
public String getBirthPlace() {
return this.birthPlace;
}
public void setBirthPlace(String birthPlace) {
this.birthPlace = birthPlace;
}
public String getBirthDate() {
return this.birthDate;
}
public void setBirthDate(int day , int month , int year){
if(day > 0 && day < 32 && month<13 && month > 0 && year < 2021){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(day).append("/").append(month).append("/").append(year);
this.birthDate = stringBuilder.toString();
}
else throw new IllegalArgumentException("IllegalArgument");
}
public String getSpuseName() {
return this.spuseName;
}
public void setSpuseName(String spuseName) {
this.spuseName = spuseName;
}
public Gender getGender() {
return this.gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public Status getStatus() {
return this.status;
}
public void setStatus(Status status) {
this.status = status;
}
public Person getSpouse() {
return this.spouse;
}
public void setSpouse(Person spouse) {
this.spouse = spouse;
this.spuseName = spouse.getFName() + " " + spouse.getLName();
}
public LinkedList<Person> getChildren() {
if(this.children == null){
this.children = new LinkedList<>();
return this.children;
}
return this.children;
}
public void setChildren(LinkedList<Person> children) {
this.children = children;
}
public Person getParent() {
return this.parent;
}
public void setParent(Person father) {
this.parent = father;
}
public List<Person> addChildrens(Person person){
this.getChildren().add(person);
return this.getChildren();
}
public String toString() {
String s = "-> [" +
"fName='" + getFName() + "'" +
", lName='" + getLName() + "'" +
", nationalId='" + getNationalId() + "'" +
", birthPlace='" + getBirthPlace() + "'" +
", birthDay='" + getBirthDate() + "'";
if(this.getParent() == null){
s += ", parentID='" + "null" + "'";
}
else{
s += ", parentName='" + getParent().getFName() + " " +getParent().getLName() +"'" ;
}
s += ", spouse='" + getSpuseName() + "'";
s += ", gender='" + getGender() + "'" +
", status='" + getStatus() + "'" +
"]";
return s;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Person)) {
return false;
}
Person person = (Person) o;
return Objects.equals(fName, person.fName) && Objects.equals(lName, person.lName) && Objects.equals(nationalId, person.nationalId) && Objects.equals(birthPlace, person.birthPlace) && Objects.equals(birthDate, person.birthDate);
}
@Override
public int hashCode() {
return Objects.hash(fName, lName, nationalId, birthPlace, birthDate);
}
}
/** this enum choose gender for any person */
enum Gender{
MALE,
FEMALE
}
/** this enum choose alive or dead status for any person */
enum Status{
A_LIVE,
DEAD
}