-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.java
65 lines (52 loc) · 1.62 KB
/
User.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
import java.io.*;
abstract class User implements Serializable {
private int id;
private String name;
private String password;
User(String name1, String password1) {
this.name = name1;
this.password = password1;
try {
File file = new File("UserID.txt");
if (!file.exists()) {
file.createNewFile();
BufferedWriter output = new BufferedWriter(new FileWriter(file, false));
output.write("0");
output.close();
} else if (file.length() == 0) {
BufferedWriter output = new BufferedWriter(new FileWriter(file, false));
output.write("0");
output.close();
}
BufferedReader reader = new BufferedReader(new FileReader(file));
this.id = Integer.parseInt(reader.readLine());
reader.close();
BufferedWriter writer = new BufferedWriter(new FileWriter(file, false));
writer.write(String.valueOf(this.id + 1));
writer.close();
} catch (IOException e) {
System.out.println("IO exception.");
}
}
int getId() {
return this.id;
}
void setId(int num) {
this.id = num;
}
String getName() {
return this.name;
}
String getUserName() {
return this.name + this.id;
}
String getPassword() {
return this.password;
}
void setPassword(String newPassword) {
this.password = newPassword;
}
public String toString() {
return this.getName() + " " + this.getId();
}
}