-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.java
99 lines (80 loc) · 1.63 KB
/
Person.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
/**
*
* @author Dilshad Haleem
* Date Written: 8/10/2019
*
*Brief Description: This class defines a Person using a name and birth year
*/
public class Person {
private String name;
private int birthYear;
/**
* Default Constructor
*/
public Person() {
this.name = "Unknown";
this.birthYear = 0;
}
/**
* Constructor
* @param name
* @param birthYear
*/
public Person(String name, int birthYear) {
this.name = name;
this.birthYear = birthYear;
}
/**
*
* @return name of the person
*/
public String getName() {
return name;
}
/**
*
* @return birthYear
*/
public int getBirthYear() {
return birthYear;
}
/**
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @param birthYear
*/
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
/**
*
* @param currentYr
* @return approximate age of a person object
*/
public int calculateAge (int currentYr) {
return currentYr - birthYear;
}
/**
*
* @param p
* @return true if the age is approximately the same.
* It is the same as if they are born in the same year
*/
public boolean equals (Person p) {
//this.birthYear is the object that is invoking/calling
//equals method and p is the parameter of the type Person
return this.birthYear == p.birthYear;
}
/**
* @return string representation of a Person object
*/
public String toString() {
return "\tName: " + this.name + "\n Birth Year: " + birthYear;
}
}