-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHuman.java
92 lines (79 loc) · 2.37 KB
/
Human.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
package com.yurii.salimov.lesson10.task05;
import java.io.Serializable;
import java.util.Scanner;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public final class Human implements Serializable {
private static final long serialVersionUID = 1L;
private final String name;
private final String surname;
private final String birth;
private String phone;
public Human(
final String name, final String surname,
final String birth, final String phone
) {
this.name = name;
this.birth = birth;
this.surname = surname;
this.phone = phone;
}
@Override
public int hashCode() {
return this.name.hashCode() + this.surname.hashCode() + this.birth.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final Human other = (Human) obj;
return (this.name.equals(other.name)) &&
(this.surname.equals(other.surname)) &&
(this.birth.equals(other.birth));
}
@Override
public Human clone() throws CloneNotSupportedException {
return (Human) super.clone();
}
@Override
public String toString() {
return "Human{" +
"name='" + this.name + '\'' +
", surname='" + this.surname + '\'' +
", birth='" + this.birth + '\'' +
", phone=" + this.phone +
'}';
}
public String getName() {
return this.name;
}
public String getSurname() {
return this.surname;
}
public String getBirth() {
return this.birth;
}
public String getPhone() {
return this.phone;
}
public static Human create(final Scanner scanner) {
System.out.print("Enter name: ");
final String name = scanner.nextLine();
System.out.print("Enter surname: ");
final String surname = scanner.nextLine();
System.out.print("Enter birth: ");
final String birth = scanner.nextLine();
System.out.print("Enter phone: ");
final String phone = scanner.nextLine();
return new Human(name, surname, birth, phone);
}
}