-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdministrator.java
More file actions
207 lines (165 loc) · 5.56 KB
/
Administrator.java
File metadata and controls
207 lines (165 loc) · 5.56 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
import java.io.*;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Scanner;
public class Administrator {
private String[] courses = {""};
private String name_std, section, email_std, name_ins, email_ins, password, degree;
Object semester;
private int age_std, age_ins, dob_std, dob_ins;
private final static String admin_pass = "welcome";
public int instructorAccount(String name, int age, String email, String degree, Object semester) {
if (!(name.matches("^[A-Za-z]*+\s?+[A-Za-z]*$")))
return 1;
name_ins = name;
if (!(email.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")))
return 1;
email_ins = email;
if (age > 65)
return 1;
age_ins = age;
if (!(degree.matches("^([^0-9]*)$")))
return 1;
this.degree = degree;
this.semester = semester;
dob_ins = (LocalDate.now().minusDays(age_ins * 365L)).getYear();
password = new DecimalFormat("#").format(Math.random() * (999999 - 111111 + 1) + 111111);
return 0;
}
//------------------------------------------------------------------------------------
public int studentAccount(String name, int age, String email, String section, Object semester) {
if (!(name.matches("^[A-Za-z]*+\s?+[A-Za-z]*$")))
return 1;
name_std = name;
if (!(section.matches("^([A-Ea-e][1,2])$")))
return 1;
this.section = section;
if (!(email.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")))
return 1;
email_std = email;
if ((age > 23) || age < 17)
return 1;
age_std = age;
dob_std = (LocalDate.now().minusDays(age_std * 365L)).getYear();
this.semester = semester;
password = new DecimalFormat("#").format(Math.random() * (999999 - 111111 + 1) + 111111);
return 0;
}
public void recordKeeping(){
try {
FileWriter fw = new FileWriter("Student_Records.txt", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.print(name_std+","+password+","+age_std+","+ email_std+","+section+","+ semester +","+dob_std+",");
for (String cours : courses) {
pw.print(cours + " ");
}
pw.print("\n");
pw.close();
}
catch(IOException e){
e.printStackTrace();
}
}
public void recordKeeping(int i){
try {
FileWriter fw1 = new FileWriter("Instructor_Records.txt", true);
BufferedWriter bw1 = new BufferedWriter(fw1);
PrintWriter pw1 = new PrintWriter(bw1);
pw1.print(name_ins+","+password+","+age_ins+","+ email_ins+","+ degree+","+ semester +","+dob_ins+",");
for (String cours : courses) {
pw1.print(cours + " ");
}
pw1.print("\n");
pw1.close();
}
catch(IOException e){
e.printStackTrace();
}
}
public int createCourse(String course,int code){
if (!(course.matches("^[A-Za-z]*+\s?+[A-Za-z]*$")))
return 1;
if (code<1000||code>9999)
return 1;
try {
FileWriter fw1 = new FileWriter("Courses.txt", true);
BufferedWriter bw1 = new BufferedWriter(fw1);
PrintWriter pw1 = new PrintWriter(bw1);
pw1.print(course+"\t"+code+"\n");
pw1.close();
}
catch(IOException e){
e.printStackTrace();
}
return 0;
}
public String courses(){
StringBuilder coursesA= new StringBuilder();
int count=1;
try {
File myObj = new File("C:\\Users\\hp 2540p\\OneDrive\\Documents\\Semester II\\OOP Lab\\Course Management System\\Courses.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
coursesA.append(count).append(").").append(data);
coursesA.append("\n");
count++;
}
myReader.close();
} catch (FileNotFoundException f) {
System.out.println("An error occurred.");
f.printStackTrace();
}
return coursesA.toString();
}
public static int logIn(String username, String pass) {
if ((pass.matches(admin_pass) && username.matches("admin")))
return 1;
else
return 0;
}
public void setCourses(String[] courses) {
this.courses= Arrays.copyOf(courses,courses.length);
}
public String getEmail_ins() {
return email_ins;
}
public String getEmail_std() {
return email_std;
}
public String getName_ins() {
return name_ins;
}
public String getName_std() {
return name_std;
}
public String getSection() {
return section;
}
public int getAge_ins() {
return age_ins;
}
public int getAge_std() {
return age_std;
}
public String[] getCourses() {
return courses;
}
public int getDob_ins() {
return dob_ins;
}
public int getDob_std() {
return dob_std;
}
public Object getSemester() {
return semester;
}
public String getPassword() {
return password;
}
public static void main(String args[]) {
MyFrame frame = new MyFrame();
}
}