-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
72 lines (67 loc) · 2.12 KB
/
Student.java
File metadata and controls
72 lines (67 loc) · 2.12 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
import java.util.ArrayList;
import java.util.List;
public class Student {
String name;
String deg;
int rollno;
int year;
List<String> coursetaken = new ArrayList<String>();
public Student(String name,int roll,String deg,int yr){
this.name = name;
this.rollno = roll;
this.deg = deg;
this.year = yr;
}
public void enroll(String a,int myidx){
int cidx=0;
for(int i=0;i<Index.c.size();i++){
if(Index.c.get(i).name.equals(a)){
cidx=i;
break;
}
}
if((Index.c.get(cidx).d.equals(Index.s.get(myidx).deg))&&(Index.c.get(cidx).yr<=Index.s.get(myidx).year)&&(Index.s.get(myidx).coursetaken.contains(Index.c.get(cidx).other)||Index.c.get(cidx).other==null)&&Index.c.get(cidx).max>0){
Index.s.get(myidx).coursetaken.add(a);
Index.c.get(cidx).studenrolled.add(Index.s.get(myidx).name);
Index.c.get(cidx).max--;
System.out.println("Enrollment_Success");
}
else{
System.out.println("Not_eligble_to_enroll_course");
}
}
public void unenroll(String a,int myidx){
int cidx=0;
for(int i=0;i<Index.c.size();i++){
if(Index.c.get(i).name.equals(a)){
cidx=i;
break;
}
}
if(Index.s.get(myidx).coursetaken.isEmpty()){
System.out.println("Nothing_to_unenroll");
}
else{
Index.s.get(myidx).coursetaken.remove(a);
Index.c.get(cidx).studenrolled.remove(Index.s.get(myidx).name);
Index.c.get(cidx).max++;
System.out.println("Unenroll_Success");
}
}
public static void show(int myidx){
System.out.println("Student_Name:" + Index.s.get(myidx).name + " ");
System.out.println("Student_Deg:" + Index.s.get(myidx).deg + " ");
System.out.println("Student_Rollno:" + Index.s.get(myidx).rollno + " ");
System.out.println("Student_Year:" + Index.s.get(myidx).year + " ");
if(Index.s.get(myidx).coursetaken.size()==0){
System.out.println("Student_courses: No_courses_enrolled");
}
else{
System.out.print("Student_courses:");
for(int i=0;i<Index.s.get(myidx).coursetaken.size();i++){
System.out.print(Index.s.get(myidx).coursetaken.get(i) + " ");
}
System.out.println();
}
}
}