-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
42 lines (32 loc) · 963 Bytes
/
Copy pathPerson.java
File metadata and controls
42 lines (32 loc) · 963 Bytes
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
import java.io.Serializable;
/**
* @author Abhiram Saran
* @version 25 Jan 2020
*/
public class Person implements Serializable {
private String name;
private int age;
public Person(String name, int age) throws NullPointerException, IllegalArgumentException {
this.name = name;
this.age = age;
if (name.equals(null)) throw new NullPointerException();
if (age < 0) throw new IllegalArgumentException();
}
public int getAge() {
return this.age;
}
public String getName() {
return this.name;
}
public boolean equals(Object object) {
if (object instanceof Person) {
return ((Person) object).name.equals(this.name) && ((Person) object).age == this.age;
} else return false;
}
public String toString() {
int a = getAge();
String n = getName();
String s = "Person[" + n + ", " + a + "]";
return s;
}
}