-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentMain.java
276 lines (241 loc) · 8.18 KB
/
StudentMain.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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import java.util.*;
import java.lang.*;
import java.io.*;
class StudentMain{
public void getProfile(Student sto){
System.out.println();
System.out.println("Name : "+sto.getName());
System.out.println("RollNo : "+sto.getRoll());
System.out.println("Branch : "+sto.getBranch());
System.out.println("Parent : "+sto.parent.getName());
System.out.println();
}
public void goMenu(Student sto){
System.out.println("================================ Hello ! "+sto.getName()+" =====================================");
System.out.println();
do{
int n;
System.out.println("(1) Show Name");
System.out.println("(2) Show Branch");
System.out.println("(3) Display GradeBook");
System.out.println("(4) Show All Students");
System.out.println("(5) Register a Subject");
System.out.println("(6) Show Registered Subjects");
System.out.println("(7) Show All Subjects");
System.out.println("(8) Show Profile");
System.out.println("(9) Add Achievements");
System.out.println("(10) Show All Achievements");
System.out.println("(11) Show All Remarks");
System.out.println("(12) Show All Fines");
System.out.println("(13) Go Back");
Scanner s = new Scanner(System.in);
n = s.nextInt();
switch(n){
case 1:
System.out.println("Hello, " +sto.getName());
System.out.println();
break;
case 2:
System.out.println("Your are "+ sto.getBranch()+" Branch");
System.out.println();
break;
case 3:
System.out.println("=======================Grade Book==========================");
System.out.println();
System.out.println("Name"+"\t"+"Internals"+"\t"+"External"+"\t"+"Grade");
for(Mark g: sto.grade.totalMarksList){
System.out.println(g.subject.name +"\t"+ g.internal +"\t\t"+ g.external +"\t\t"+ g.grade);
}
System.out.println();
System.out.println("===========================================================");
break;
case 4:
for(Student stud : Student.totalStudentsList){
System.out.println(stud.getName());
}
System.out.println();
break;
case 5:
System.out.println();
System.out.println("======================= Register a Subject ==================");
while(true){
System.out.println("Enter Subject Name:");
String name = s.next();
System.out.println("Enter the Course Code");
String course = s.next();
Subject su = SubjectMain.returnSub(course);
if( su != null){
if(!sto.checkRegSub(course)){
sto.addSub(su);
sto.save();
// StudentMain.saveStud();
System.out.println("Saved.. ");
break;
}
}
}
System.out.println();
break;
case 6:
System.out.println();
System.out.println("================Registered Subjects==============");
System.out.println();
System.out.println(sto.registeredSub);
for(Subject sub : sto.registeredSub){
System.out.println(sub.getsubName()+" "+sub.getsubCourseCode());
}
System.out.println();
System.out.println("=================================================");
System.out.println();
break;
case 7:
System.out.println();
System.out.println("================Subjects==============");
System.out.println();
for(Subject sub : Subject.totalSubjectslist){
System.out.println(sub.getsubName()+" "+sub.getsubCourseCode());
}
System.out.println();
System.out.println("=======================================");
System.out.println();
break;
case 8:
getProfile(sto);
break;
case 9:
System.out.println();
System.out.println("================== Add Achievements ===================");
System.out.println();
while(true){
System.out.println("Enter the type of Achievement :");
String achName = s.next();
System.out.println("Give any Description of Achievement");
String achDes = s.nextLine();
Achievement ac = new Achievement(achName,achDes);
if(achName!= null){
sto.addAch(ac);
sto.save();
System.out.println("Saved..");
System.out.println("==================================================");
break;
}
}
break;
case 10:
System.out.println();
System.out.println("=================== All Achievements =======================");
System.out.println();
System.out.println("Type of Acheivement\tDescripption");
for(Achievement ac : sto.achievement){
System.out.println(ac.getName()+"\t\t\t"+ac.getMsg());
}
System.out.println();
System.out.println("============================================================");
System.out.println();
break;
case 11:
System.out.println();
System.out.println("======================== All Remarks =========================");
System.out.println();
System.out.println("From "+"\t\t"+"Description");
for(Memo m : sto.memos){
System.out.println(m.from.getName()+"\t\t"+m.getMsg());
}
System.out.println();
System.out.println("==============================================================");
System.out.println();
break;
case 12:
System.out.println();
System.out.println("======================== All Fines =========================");
System.out.println();
System.out.println("From "+"\t\t"+"Description"+"\t\t"+"Date");
for(Fine m : sto.fines){
System.out.println(m.from.getName()+"\t\t"+m.getMsg()+"\t\t\t"+m.date);
}
System.out.println();
System.out.println("==============================================================");
System.out.println();
break;
case 13:
return;
default :
// System.out.println("Enter Valid number");
Scanner input = new Scanner(System.in);
System.out.println("Enter roll no:");
sto.setRoll(input.next());
sto.save();
}
}
while(true);
}
public static void saveStud(){
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try{
fos = new FileOutputStream("Data/Students.ser");
oos = new ObjectOutputStream(fos);
oos.writeObject(Student.totalStudentsList);
oos.flush();
oos.close();
}
catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}
}
public static ArrayList<Student> getStud(){
FileInputStream fis = null;
ObjectInputStream ois = null;
ArrayList<Student> listOfStudents = null;
try {
// reading binary data
fis = new FileInputStream("Data/Students.ser");
// converting binary-data to java-object
ois = new ObjectInputStream(fis);
// reading object's value and casting ArrayList<Customer>
listOfStudents = (ArrayList<Student>) ois.readObject();
}
catch (FileNotFoundException fnfex) {
fnfex.printStackTrace();
}
catch (IOException ioex) {
ioex.printStackTrace();
}
catch (ClassNotFoundException ccex) {
ccex.printStackTrace();
}
// for(Student stud : listOfStudents){
// System.out.println(stud.getRoll());
// }
return listOfStudents;
}
public static Student checkRoll(String a){
Student pres = null;
for(Student st :Student.totalStudentsList){
if(st.getRoll().equals(a)){
return st;
}
else{
try{
throw new MyException("not found");
}
catch(MyException ex){System.out.println(ex);}
}
}
return null;
}
public boolean isStudent(String a){
ArrayList<Student> objstud = StudentMain.getStud();
Student pres = null;
for(Student st : objstud){
if(st.getRoll().equals(a)){
return true;
}
}
return false;
}
//////// Add Marks
}