-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerson.java
More file actions
95 lines (71 loc) · 1.56 KB
/
Copy pathPerson.java
File metadata and controls
95 lines (71 loc) · 1.56 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
public class Person {
int age;
private String fname;
private String lname;
static int count = 0;
public Person(String fname, String lname) {
this.fname = fname;
this.lname = lname;
count++;
}
/** Mutator method for age
* @param age - age to set
*/
public void setAge(int age) {
this.age = age;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getFname() {
return this.fname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getLname() {
return this.fname;
}
/** Accessor method for age
* @return the current age
*/
public int getAge() {
return(age);
}
public String toString() {
return fname + " " + lname + " " + count;
}
public boolean equals(Object rhs) {
if ( !(rhs instanceof Person) ) {
return false;
}
Person other = (Person) rhs;
if ( (this.age == other.age) &&
(this.fname.equals(other.fname)) &&
(this.lname.equals(other.lname) ) ) {
return true;
}
return false;
}
public static void main (String[] args) {
Person p1 = new Person("Roberto", "Hoyle");
p1.setAge(44);
System.out.println(p1);
Person p2 = new Person("Maia", "Hoyle");
p2.setAge(8);
System.out.println(p1);
System.out.println(p2);
Person p3 = new Person("Roberto", "Hoyle");
p3.setAge(44);
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
if (p1 == p3) {
System.out.println("There is something weird...");
}
if (p1.equals(p3)) {
System.out.println("That is more like it!");
}
System.out.println("I ran!");
}
}