-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.java
More file actions
153 lines (147 loc) · 3.78 KB
/
Index.java
File metadata and controls
153 lines (147 loc) · 3.78 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class Index {
static List<Prof> p = new ArrayList<Prof>();
static List<Course> c = new ArrayList<Course>();
static List<Student> s = new ArrayList<Student>();
public static void main(String[] args) throws FileNotFoundException {
Scanner ip = new Scanner(new File("input.txt"));
int x,y,yr;
String a,b,n,d,input;
while(ip.hasNext()){
input = ip.next();
if(input.equalsIgnoreCase("ADDS")){
a = ip.next();
x = ip.nextInt();
b = ip.next();
y = ip.nextInt();
s.add(new Student(a,x,b,y));
}
else if(input.equalsIgnoreCase("ADDP")){
a = ip.next();
b = ip.next();
p.add(new Prof(a,b));
}
else if(input.equalsIgnoreCase("ADDC")){
a = ip.next();
x = ip.nextInt();
b = ip.next();
d = ip.next();
yr = ip.nextInt();
n = ip.next();
if(ccheck(a)){
System.out.println("Course_Already_Exists");
}
else{
if(pcheck(b,a)){
if(n.compareTo("NULL")==0)
c.add(new Course(a,x,b,d,yr));
else
c.add(new Course(a,x,b,d,yr,n));
}
else
System.out.println("No_such_Professor");
}
}
else if(input.equalsIgnoreCase("ENROLL")){
a = ip.next();
b = ip.next();
int temp = scheck(b);
if(s.size()==0||temp==s.size())
System.out.println("No_such_Student");
else {
Student t = s.get(temp);
if(s.get(temp).coursetaken.contains(a))
System.out.println("Course_Already_Enrolled");
else
t.enroll(a,temp);
}
}
else if(input.equalsIgnoreCase("UNENROLL")){
a = ip.next();
b = ip.next();
int temp = scheck(b);
if(s.size()==0||temp==s.size())
System.out.println("No_such_Student");
else {
Student t = s.get(temp);
if(s.get(temp).coursetaken.contains(a))
t.unenroll(a,temp);
else
System.out.println("Course_not_found_to_unroll");
}
}
else if(input.equalsIgnoreCase("SHOWS")){
a = ip.next();
int temp = scheck(a);
if(s.size()==0||temp==s.size())
System.out.println("No_such_Student");
else {
Student.show(temp);
}
}
else if(input.equalsIgnoreCase("SHOWC")){
a = ip.next();
if(ccheck(a))
Course.show(a);
else
System.out.println("No_Such_Course");
}
else if(input.equalsIgnoreCase("MODIFY")){
a = ip.next();
x = ip.nextInt();
b = ip.next();
if(ccheck(a)){
if(pcheck(b,a)){
Course.modify(a,x,b);
System.out.println("Modify_Success");
}
else
System.out.println("No_Such_Professor_to_Modify_in_course");
}
else
System.out.println("No_Such_Course_to_Modify");
}
else if(input.equalsIgnoreCase("SHOWP")){
a = ip.next();
int pidx = pcheck2(a);
if(p.size()==0||pidx==p.size())
System.out.println("No_Such_Professor");
else
Prof.show(pidx); }
}
ip.close();
}
public static int scheck(String name){
for(int i=0;i<s.size();i++){
if(s.get(i).name.equals(name))
return i;
}
return 0;
}
public static boolean pcheck(String name,String course){
for(int i=0;i<p.size();i++){
if(p.get(i).name.equals(name)){
p.get(i).coursetaking.add(course);
return true;
}
}
return false;
}
public static int pcheck2(String name){
for(int i=0;i<p.size();i++){
if(p.get(i).name.equals(name)){
return i;
}
}
return 0;
}
public static boolean ccheck(String name){
for(int i=0;i<c.size();i++){
if(c.get(i).name.equals(name))
return true;
}
return false;
}
}