-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
136 lines (131 loc) · 3.93 KB
/
Account.java
File metadata and controls
136 lines (131 loc) · 3.93 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
package finalProject;
import java.io.*;
import java.util.ArrayList;
import finalProject.Manager;
import finalProject.Student;
import finalProject.Professor;
public class Account {
String account;
String password;
String identity;
public Account(String account, String password, String identity) {
this.account = account;
this.password = password;
this.identity = identity;
}
public boolean logIn() { //驗證帳號_待依GUI修改
String account;
String password;
String identity;
String fileName = this.account;
String path = "C:\\StudentGradeSystem\\AccountFile\\" + fileName +".txt";
File newFile = new File(path);
if (!newFile.exists()) {
return false;
}
else {
try {
FileInputStream fis = new FileInputStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
account = br.readLine();
password = br.readLine();
identity = br.readLine();
if (account.equals(this.account) &&
password.equals(this.password) &&
identity.equals(this.identity)) {
br.close();
return true;
}
else {
br.close();
return false;
}
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
public Object changeType(String id) { //變更物件_OK //用於管理員、教授、學生導入資料
String fileName = this.account;
String path = "C:\\StudentGradeSystem\\AccountFile\\" + fileName +".txt";
int x = 0;
if (id.equals("管理員")) {
x = 1;
}
else if (id.equals("學生")) {
x = 2;
}
if (id.equals("教授")) {
x = 3;
}
switch (x) {
case 1: //管理員
try {
FileInputStream fis = new FileInputStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String account = br.readLine();
String password = br.readLine();
String identity = br.readLine();
Manager changetypeFile = new Manager(account, password, identity);
br.close();
return changetypeFile;
} catch (IOException e) {
e.printStackTrace();
}
break;
case 2: //學生
try {
FileInputStream fis = new FileInputStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String account = br.readLine();
String password = br.readLine();
String identity = br.readLine();
String name = br.readLine();
String year = br.readLine();
ArrayList<ArrayList<String>> lesson = new ArrayList<ArrayList<String>>();
String line;
while ((line = br.readLine()) != null) {
ArrayList<String> yearLesson = new ArrayList<String>();
String[] getLesson = line.split(" ");
for (int i = 0; i < getLesson.length; i++) {
yearLesson.add(getLesson[i]);
}
lesson.add(yearLesson);
}
Student changetypeFile = new Student(account, password, identity, name, year, lesson);
br.close();
return changetypeFile;
} catch (IOException e) {
e.printStackTrace();
}
break;
case 3: //教授
try {
FileInputStream fis = new FileInputStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String account = br.readLine();
String password = br.readLine();
String identity = br.readLine();
String name = br.readLine();
ArrayList<ArrayList<String>> lesson = new ArrayList<ArrayList<String>>();
String line;
while ((line = br.readLine()) != null) {
ArrayList<String> yearLesson = new ArrayList<String>();
String[] getLesson = line.split(" ");
for (int i = 0; i < getLesson.length; i++) {
yearLesson.add(getLesson[i]);
}
lesson.add(yearLesson);
}
Professor changetypeFile = new Professor(account, password, identity, name, lesson);
br.close();
return changetypeFile;
} catch (IOException e) {
e.printStackTrace();
}
break;
}
return null;
}
}