This repository was archived by the owner on Dec 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPerson.java
More file actions
258 lines (226 loc) · 6.75 KB
/
Copy pathPerson.java
File metadata and controls
258 lines (226 loc) · 6.75 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package com.library.component;
import com.library.main.Library;
import com.library.util.Day;
import java.util.Scanner;
public abstract class Person {
private String status;
private int id;
private String name;
private Day dob;
private String gender;
private String phone;
private String address;
private String email;
public Person() {
this.status = "enabled";
this.id = 0;
this.name = "";
this.dob = new Day();
this.gender = "";
this.phone = "";
this.address = "";
this.email = "";
}
public Person(String status, int id, String name, Day dob, String gender, String phone, String address, String email) {
this.status = status;
this.id = id;
this.name = name;
this.dob = dob;
this.gender = gender;
this.phone = phone;
this.address = address;
this.email = email;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Day getDob() {
return dob;
}
public void setDob(Day dob) {
this.dob = dob;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void input() {
int id;
do {
id = inputId("Enter ID (8 digits): ");
if (Library.getStudentManagement().idExists(id) || Library.getEmployeeManagement().idExists(id))
System.out.println("ID has been used!");
else
break;
} while (true);
this.id = id;
name = inputName("Enter name: ");
dob = inputDob("Enter date of birth (dd/mm/yyyy): ");
gender = inputGender("Enter gender (Nam|Nữ): ");
phone = inputPhone("Enter phone (10 digits): ");
address = inputAddress("Enter address (city): ");
email = inputEmail("Enter email: ");
}
public static int inputId(String message) {
Scanner sc = new Scanner(System.in);
String input;
int id = 0;
boolean hasError;
do {
hasError = false;
System.out.print(message);
input = sc.nextLine();
try {
id = Integer.parseInt(input);
if (input.length() != 8) {
System.out.println("ID must have 8 digits!");
hasError = true;
} else if (id < 0) {
System.out.println("ID must be a positive number!");
hasError = true;
}
} catch (Exception e) {
hasError = true;
}
} while (hasError);
return id;
}
public static String inputName(String message) {
Scanner sc = new Scanner(System.in);
String name;
do {
System.out.print(message);
name = sc.nextLine();
} while (name.length() == 0);
return name;
}
public static Day inputDob(String message) {
Scanner sc = new Scanner(System.in);
String input;
String[] day;
Day dob = new Day();
boolean hasError;
do {
hasError = false;
System.out.print(message);
input = sc.nextLine();
day = input.split("/");
try {
dob.setDate(Integer.parseInt(day[0]));
dob.setMonth(Integer.parseInt(day[1]));
dob.setYear(Integer.parseInt(day[2]));
if (!Day.isValidDay(dob)) {
System.out.println("Date of birth is not valid!");
hasError = true;
}
} catch (Exception e) {
hasError = true;
}
} while (hasError || !Day.isValidDay(dob));
return dob;
}
public static String inputGender(String message) {
Scanner sc = new Scanner(System.in);
String gender;
boolean hasError;
do {
hasError = false;
System.out.print(message);
gender = sc.nextLine();
if (!gender.equalsIgnoreCase("Nam") && !gender.equalsIgnoreCase("Nữ")) {
System.out.println("Gender must be \"Nam\" or \"Nữ\"!");
hasError = true;
}
} while (hasError);
if (gender.equalsIgnoreCase("Nam"))
gender = "Nam";
else
gender = "Nữ";
return gender;
}
public static String inputPhone(String message) {
Scanner sc = new Scanner(System.in);
String phone;
boolean hasError;
do {
hasError = false;
System.out.print(message);
phone = sc.nextLine();
if (phone.length() != 10) {
System.out.println("Phone number must have 10 digits!");
hasError = true;
}
} while (hasError);
return phone;
}
public static String inputAddress(String message) {
Scanner sc = new Scanner(System.in);
String address;
do {
System.out.print(message);
address = sc.nextLine();
} while (address.isBlank());
return address;
}
public static String inputEmail(String message) {
Scanner sc = new Scanner(System.in);
String email;
do {
System.out.print(message);
email = sc.nextLine();
} while (email.isBlank());
return email;
}
public void output() {
System.out.printf("%10d |%24s | ", id, name);
System.out.print(dob + " |");
System.out.printf("%6s |%12s |%18s |%25s |", gender, phone, address, email);
}
public abstract double calculatePrice(Day borrowDay, Day returnDay, int numOfBooks);
@Override
public String toString() {
return status + ", " +
id + ", " +
name + ", " +
dob + ", " +
gender + ", " +
phone + ", " +
address + ", " +
email + ", ";
}
}