-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
841 lines (651 loc) · 20.4 KB
/
main.java
File metadata and controls
841 lines (651 loc) · 20.4 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
import java.util.*;
import java.io.*;
class User{
private String id = "Admin";
private String name = "Admin";
private String pass = "123";
public User() {};
public User(String name, String id, String pass ) {
this.id = id;
this.name = name;
this.pass = pass;
}
public void set_id(String id) {
this.id = id;
}
public void set_name(String name) {
this.name = name;
}
public void set_pass(String pass) {
this.pass = pass;
}
public String get_id() {
return id;
}
public String get_Name() {
return name;
}
public String get_Pass(){
return pass;
}
}
class Student extends User{
private int curr_class;
private int attendance;
private ArrayList<Course> courses;
public Student(String name, String id, String password, int curr_class){
super(name, id, password);
this.curr_class = curr_class;
courses = new ArrayList<Course>();
}
public ArrayList<Course> getCourses() {
return courses;
}
public void setCourseObjects(ArrayList<String> crs) {
for(String st: crs) {
courses.add(new Course(st));
}
}
public int searchCourseObject(String courseName){
for(int i=0; i<courses.size(); i++){
Course c = courses.get(i);
//System.out.println(c.getCourseName());
if(c.getCourseName().equals(courseName)){
return i;
}
}
return -1;
}
public void printCourseDetails() {
for(Course c: courses) {
System.out.println(c.getCourseName()+" "+c.getMarks()+ " "+c.getGrades());
}
}
public void modifyStudentDetail(String name, String id, String password, int curr_class) {
set_id(id);
set_name(name);
set_pass(password);
this.curr_class=curr_class;
}
public void set_Password(String pswd){
set_pass(pswd);
}
public int getAttendance() {
return attendance;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
public void viewDetails(){
System.out.println("Name: " + get_Name() + ", Class: " + curr_class + ", ID: "+ get_id());
System.out.println("Attendance : "+getAttendance());
System.out.println("Courses Marks Grades");
printCourseDetails();
}
public void viewDetailsOnly(){
System.out.println("Name: " + get_Name() + ", Class: " + curr_class + ", ID: "+ get_id());
}
}
class Teacher extends User{
private ArrayList <String> courses;
public Teacher(String name, String id, String password, ArrayList<String> courses){
super(name, id, password);
this.courses =courses;
}
public void modifyTeacherDetail(String name, String id, String password) {
set_id(id);
set_name(name);
set_pass(password);
}
public void set_Password(String pswd){
set_pass(pswd);
}
public void viewCourses() {
for(String s: courses) {
System.out.println(s);
}
}
public void viewDetails(){
System.out.println("Name: " + get_Name() +", ID: "+ get_id());
System.out.println("Courses: ");
for(String course:courses) {
System.out.print(course+" ");
}
}
public void viewDetailsOnly(){
System.out.println("Name: " + get_Name() +", ID: "+ get_id());
}
}
class Admin extends User{
ArrayList <Student> stud_data;
ArrayList <Teacher> teacher_data;
private ArrayList<Classroom> clrmList;
private ArrayList<ArrayList<String>> courses = new ArrayList<>();
public Admin (ArrayList<Student> s_data, ArrayList<Teacher> t_data) {
this.stud_data = s_data;
this.teacher_data = t_data;
}
public ArrayList<Student> add_student(String name, int curr_class, String id, String password, ArrayList<Classroom> clrmList) {
Student s = new Student(name, id, password, curr_class);
this.clrmList=clrmList;
stud_data.add(s);
Classroom c = clrmList.get(curr_class-1);
c.setClassroom_students(s);
return stud_data;
}
public ArrayList<Teacher> add_teacher(String name, String id, String password, ArrayList<String> courses) {
Teacher t = new Teacher(name, id, password, courses);
teacher_data.add(t);
return teacher_data;
}
public int search_student_byName(String name){
for(int i=0; i<stud_data.size(); i++){
Student s = stud_data.get(i);
if(s.get_Name().equals(name)){
return i;
}
}
return -1;
}
public int search_student_byID(String id){
for(int i=0; i<stud_data.size(); i++){
Student s = stud_data.get(i);
if(s.get_id().equals(id)){
return i;
}
}
return -1;
}
public int search_teacher_byName(String name){
for(int i=0; i<teacher_data.size(); i++){
Teacher t = teacher_data.get(i);
if(t.get_Name().equals(name)){
return i;
}
}
return -1;
}
public int search_teacher_byID(String id){
for(int i=0; i<teacher_data.size(); i++){
Teacher t = teacher_data.get(i);
if(t.get_id().equals(id)){
return i;
}
}
return -1;
}
public ArrayList<Student> remove_student(int n, String str){
if(n==1){
int idx_student = search_student_byName(str);
stud_data.remove(idx_student);
}
else{
int idx_student = search_student_byID(str);
stud_data.remove(idx_student);
}
return stud_data;
}
public ArrayList<Student> modify_student(int n, String str, String name, String id, String password, int curr_class){
if(n==1){
int idx_student = search_student_byName(str);
stud_data.get(idx_student).modifyStudentDetail(name, id, password, curr_class);
}
else{
int idx_student = search_student_byID(str);
stud_data.get(idx_student).modifyStudentDetail(name, id, password, curr_class);
}
return stud_data;
}
public ArrayList<Teacher> modify_teacher(int n, String str, String name, String id, String password){
if(n==1){
int idx_teacher = search_teacher_byName(str);
teacher_data.get(idx_teacher).modifyTeacherDetail(name, id, password);
}
else{
int idx_teacher = search_student_byID(str);
teacher_data.get(idx_teacher).modifyTeacherDetail(name, id, password);
}
return teacher_data;
}
public ArrayList<Teacher> remove_teacher(int n, String str){
if(n==1){
int idx_teacher = search_teacher_byName(str);
teacher_data.remove(idx_teacher);
}
else{
int idx_teacher = search_teacher_byID(str);
teacher_data.remove(idx_teacher);
}
return teacher_data;
}
public void view_Details_Students(){
System.out.println("Student details are :-");
for(Student s: stud_data){
s.viewDetailsOnly();
}
}
public ArrayList<Classroom> add_courses(int cl, ArrayList<String> courses) {
clrmList.get(cl-1).setCourses(courses);
clrmList.get(cl-1).viewCourses();
return clrmList;
}
public void view_Details_Teachers(){
for(Teacher t: teacher_data){
t.viewDetailsOnly();
}
}
}
class Course{
private String courseName;
private int marks;
private String grades;
public Course(String courseName){
this.courseName=courseName;
}
public String getCourseName() {
return courseName;
}
public int getMarks() {
return marks;
}
public String getGrades() {
return grades;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setMarks(int marks) {
this.marks = marks;
}
public void setGrades(String grades) {
this.grades = grades;
}
}
class Classroom {
private int cl;
private ArrayList<Student> classroom_students;
private ArrayList<String> courses;
public Classroom(int cl, ArrayList<String> courses){
this.cl=cl;
//System.out.println("Welcome to class "+cl);
classroom_students = new ArrayList<Student>();
this.courses=courses;
}
public void viewCourses() {
for(String str: courses)
System.out.println(str);
}
public void viewStudents() {
for(Student st: classroom_students)
System.out.println(st.get_Name());
}
public ArrayList<String> getCourses() {
return courses;
}
public void setCourses(ArrayList<String> courses) {
this.courses = courses;
}
public ArrayList<Student> getClassroom_students() {
return classroom_students;
}
public void setClassroom_students(Student s) {
classroom_students.add(s);
s.setCourseObjects(courses);
}
}
public class main{
public static ArrayList <Student> s_data = new ArrayList<Student>();
public static ArrayList <Teacher> t_data = new ArrayList<Teacher>();
static int search_student_byName(String name){
for(int i=0; i<s_data.size(); i++){
Student s = s_data.get(i);
if(s.get_Name().equals(name)){
return i;
}
}
return -1;
}
static int search_student_byID(String id){
for(int i=0; i<s_data.size(); i++){
Student s = s_data.get(i);
if(s.get_id().equals(id)){
return i;
}
}
return -1;
}
static int search_teacher_byName(String name){
for(int i=0; i<t_data.size(); i++){
Teacher t = t_data.get(i);
if(t.get_Name().equals(name)){
return i;
}
}
return -1;
}
static int search_teacher_byID(String id){
for(int i=0; i<t_data.size(); i++){
Teacher t = t_data.get(i);
if(t.get_id().equals(id)){
return i;
}
}
return -1;
}
public static void main(String[] args) throws NumberFormatException, IOException {
System.out.println("----------WELCOME TO THE STUDENT MANAGEMENT SYSTEM-------");
System.out.println();
ArrayList<Classroom> clrmList = new ArrayList<Classroom>(13);
ArrayList<ArrayList<String>> coursesArrayList = new ArrayList<>(12);
int j=1;
for(int i=0;i<12;i++) {
ArrayList<String> arr = new ArrayList<String>();
arr.add("HINDI"+j);
arr.add("ENGLISH"+j);
arr.add("MATH"+j);
arr.add("SCIENCE"+j);
arr.add("SOCIAL"+j);
j++;
coursesArrayList.add(arr);
}
for(int i=0; i<12; i++) {
clrmList.add(new Classroom((i+1),coursesArrayList.get(i)));
}
//Starting Point
while(true){
System.out.println("Login to the System:-");
System.out.println("Enter: 1 - Admin");
System.out.println(" 2 - Teacher");
System.out.println(" 3 - Student");
System.out.println(" 4 - Exit");
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int num_login = Integer.parseInt(br.readLine());
System.out.println();
Admin admin = new Admin(s_data, t_data);
ArrayList<String> arr1 = new ArrayList<String>();
arr1.add("HINDI12");
arr1.add("ENGLISH12");
arr1.add("MATH10");
ArrayList<String> arr2 = new ArrayList<String>();
arr2.add("SCIENCE10");
arr2.add("SOCIAL12");
admin.add_teacher("Megha Somani", "2019T001","2019T001",arr1);
admin.add_teacher("Mamta Menariya", "2019T002","2019T002",arr2);
if(num_login==1){
System.out.println("Enter ID");
String login_id_admin = br.readLine();
System.out.println("Enter Password");
String login_pswd_admin = br.readLine();
System.out.println();
if(admin.get_Name().equals(login_id_admin)&&admin.get_Pass().equals(login_pswd_admin)) {
System.out.println("-----Hello! Admin----");
}
else {
System.out.println("Invalid details !!");
System.out.println();
continue;
}
while(true) {
System.out.println("Enter: 1 - Add Student");
System.out.println(" 2 - Remove Student");
System.out.println(" 3 - Modify Student details");
System.out.println(" 4 - Add Teacher");
System.out.println(" 5 - Remove Teacher");
System.out.println(" 6 - Modify Teacher details");
System.out.println(" 7 - View Student Details");
System.out.println(" 8 - View Teacher Details");
System.out.println(" 9 - Exit");
int num_admin = Integer.parseInt(br.readLine());
System.out.println();
if(num_admin == 1){
System.out.println("Enter the name, class, id of the student to be added.");
String[] str = new String[3];
for(int i=0; i<3; i++) {
str[i] = br.readLine();
}
String passwordString =str[2];
s_data = admin.add_student(str[0], Integer.parseInt(str[1]), str[2], passwordString, clrmList);
System.out.println("Student successfully added.");
System.out.println();
continue;
}
if(num_admin == 2){
System.out.println("Enter: 1 - Remove by Name");
System.out.println(" 2 - Remove by ID");
int num_remove = Integer.parseInt(br.readLine());
System.out.println("Type the name/ID");
String nameOrID = br.readLine();
s_data = admin.remove_student(num_remove, nameOrID);
System.out.println("Student successfully removed.");
System.out.println();
continue;
}
if(num_admin==3) {
System.out.println("Enter: 1 - Modify by Name");
System.out.println(" 2 - Modify by ID");
int num_modify = Integer.parseInt(br.readLine());
System.out.println("Type the name/ID");
String nameOrID = br.readLine();
System.out.println("Enter new name, id, class.");
String[] str = new String[3];
for(int i=0; i<3; i++) {
str[i] = br.readLine();
}
String passwordString =str[1];
s_data = admin.modify_student(num_modify, nameOrID, str[0], str[1], passwordString, Integer.parseInt(str[2]));
System.out.println("Student details successfully modified.");
System.out.println();
//admin.view_Details_Students();
continue;
}
if(num_admin == 4){
System.out.println("Enter the name, id of the teacher to be added. Also add the no. of courses he/she will teach and name them.");
String[] str = new String[2];
for(int i=0; i<2; i++) {
str[i] = br.readLine();
}
int b = Integer.parseInt(br.readLine());
ArrayList<String> courseTeach = new ArrayList<>();
for(int i=0; i<b; i++) {
courseTeach.add(br.readLine());
}
String passwordString =str[1];
t_data = admin.add_teacher(str[0], str[1], passwordString, courseTeach);
System.out.println("Teacher successfully added.");
System.out.println();
//admin.view_Details_Teachers();
continue;
}
if(num_admin == 5){
System.out.println("Enter: 1 - Remove by Name");
System.out.println(" 2 - Remove by ID");
int num_remove = Integer.parseInt(br.readLine());
System.out.println("Type the name/ID");
String nameOrID = br.readLine();
t_data = admin.remove_teacher(num_remove, nameOrID);
System.out.println("Teacher successfully removed.");
System.out.println();
continue;
}
if(num_admin==6) {
System.out.println("Enter: 1 - Modify by Name");
System.out.println(" 2 - Modify by ID");
int num_modify = Integer.parseInt(br.readLine());
System.out.println("Type the name/ID");
String nameOrID = br.readLine();
System.out.println("Enter new name, id.");
String[] str = new String[3];
for(int i=0; i<2; i++) {
str[i] = br.readLine();
}
String passwordString =str[1];
t_data = admin.modify_teacher(num_modify, nameOrID, str[0], str[1], passwordString);
System.out.println("Teacher details successfully modified.");
System.out.println();
continue;
}
if(num_admin==7){
admin.view_Details_Students();
System.out.println();
continue;
}
if(num_admin==8){
admin.view_Details_Teachers();
System.out.println();
continue;
}
if(num_admin==9){
System.out.println("-----Thank You admin----");
System.out.println();
break;
}
}
}
else if(num_login==2){
System.out.println("Enter ID");
String login_id = br.readLine();
System.out.println("Enter Password");
String login_pswd = br.readLine();
int idx =search_teacher_byID(login_id);
if(idx>=0) {
if(t_data.get(idx).get_Pass().equals(login_pswd)) {
System.out.println("-----Hello! Teacher----");
System.out.println();
}
else {
System.out.println("Wrong Password");
System.out.println();
continue;
}
}
else {
System.out.print("Wrong id.");
System.out.println();
continue;
}
while(true) {
System.out.println("Enter: 1 - To Enter Attendance of the students");
System.out.println(" 2 - To enter marks and grades of a whole class in a particular subject");
System.out.println(" 3 - Set Password");
System.out.println(" 4 - View Details");
System.out.println(" 5 - Exit");
int num_teach = Integer.parseInt(br.readLine());
System.out.println();
if(num_teach==1) {
System.out.println("Enter the class");
int classNo = Integer.parseInt(br.readLine());
System.out.println("(Add attendance student wise)");
ArrayList<Student> students = clrmList.get(classNo-1).getClassroom_students();
for(Student st: students) {
System.out.print(st.get_Name()+" :");
int att = Integer.parseInt(br.readLine());
st.setAttendance(att);
}
System.out.println("Attendance successsfully added");
System.out.println();
}
if(num_teach==2) {
System.out.println("Type the class and course name among your courses shown below: ");
System.out.println();
Teacher teacher = t_data.get(idx);
teacher.viewCourses();
int cl = Integer.parseInt(br.readLine());
String string = br.readLine();
//System.out.println(string);
System.out.println();
Classroom classroom = clrmList.get(cl-1);
ArrayList<Student> students = classroom.getClassroom_students();
System.out.println("Enter the marks and grades studentwise.");
for(Student st: students) {
System.out.print(st.get_Name()+" : ");
int indx = st.searchCourseObject(string);
//System.out.println(indx);
if(idx<0) {
System.out.print("Course doesnot exist");
System.out.println();
continue;
}
st.getCourses().get(indx).setMarks(Integer.parseInt(br.readLine()));
st.getCourses().get(indx).setGrades(br.readLine());
}
System.out.println("Successsfully added");
System.out.println();
}
if(num_teach==3) {
Teacher teacher = t_data.get(idx);
System.out.print("Enter new Password : ");
teacher.set_pass(br.readLine());
System.out.println("Password reset successfully.");
System.out.println();
}
if(num_teach==4) {
Teacher teacher = t_data.get(idx);
teacher.viewDetails();
System.out.println();
}
if(num_teach==5) {
System.out.println("-----Thank You Teacher----");
System.out.println();
break;
}
}
}
else if(num_login==3){
System.out.println("Enter ID");
String login_id = br.readLine();
System.out.println("Enter Password");
String login_pswd = br.readLine();
int idx =search_student_byID(login_id);
if(idx>=0) {
if(s_data.get(idx).get_Pass().equals(login_pswd)) {
System.out.println("-----Hello! Student----");
System.out.println();
}
else {
System.out.println("Wrong Password");
System.out.println();
continue;
}
}
else {
System.out.print("Wrong id.");
System.out.println();
continue;
}
while(true) {
System.out.println("Enter: 1 - Set Password");
System.out.println(" 2 - View Details");
System.out.println(" 3 - Exit");
int num_teach = Integer.parseInt(br.readLine());
System.out.println();
if(num_teach==1) {
Student student = s_data.get(idx);
System.out.print("Enter new Password : ");
student.set_pass(br.readLine());
System.out.println("Password reset successfully.");
System.out.println();
}
if(num_teach==2) {
Student student = s_data.get(idx);
student.viewDetails();
System.out.println();
}
if(num_teach==3) {
System.out.println("-----Thank You Student----");
System.out.println();
break;
}
}
}
else if(num_login==4){
System.out.println("-----Thank You----");
break;
}
else{
System.out.println("-----Invalid number----");
System.out.println();
continue;
}
}
}
}