-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLA1.java
More file actions
365 lines (332 loc) · 13.3 KB
/
LA1.java
File metadata and controls
365 lines (332 loc) · 13.3 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
import java.util.*;
class Student{
private final int roll;
private final String branch;
private final float cgpa;
private String placement_status;
Student(int roll, float cgpa, String branch, String placement_status){
this.roll=roll;
this.branch=branch;
this.cgpa=cgpa;
this.placement_status=placement_status;
}
public String getbranch(){
return this.branch;
}
public int getroll(){
return this.roll;
}
public float getgpa(){
return this.cgpa;
}
public void show_student_details(){
System.out.println(this.roll);
System.out.println(this.cgpa);
System.out.println(this.branch);
System.out.println("Placement Status : "+this.placement_status);
}
}
class Company{
private final String company_name;
private int number_of_required_students;
private String application_status;
private ArrayList<String> eligiblecourses_arr;
private int number_of_eligible_courses;
private int[][] techincalscores;
private int total_students;
Company(String company_name,int number_of_eligible_courses,ArrayList<String> eligiblecourses_arr,int number_of_required_students,int number_of_students){
this.company_name=company_name;
this.number_of_eligible_courses=number_of_eligible_courses;
this.eligiblecourses_arr=eligiblecourses_arr;
this.number_of_required_students=number_of_required_students;
this.application_status="OPEN";
this.total_students=number_of_students;
this.techincalscores = new int[2][number_of_students];
}
public int getnumber_of_required_students(){
return number_of_required_students;
}
public int gettotal_students(){
return this.total_students;
}
public int[][] gettechnicalscores(){
return this.techincalscores;
}
public ArrayList<String> geteligiblecourses_arr(){
return this.eligiblecourses_arr;
}
public String getapplication_status(){
return this.application_status;
}
public String getcompany_name(){
return this.company_name;
}
public void setapplicationstatus(){
this.application_status="CLOSED";
}
public void show_company_details(){
System.out.println(this.company_name);
System.out.println("Course Criteria");
for(int i=0;i<this.eligiblecourses_arr.size();i++){
System.out.println(this.eligiblecourses_arr.get(i));
}
System.out.println("Number of Required Students = "+this.number_of_required_students);
System.out.println("Application Status = "+ this.application_status);
}
}
class Placement_Office{
private ArrayList<Student> ongoingplacements_arr;
private ArrayList<Student> placedstudents_arr;
private ArrayList<Student> students_arr;
private ArrayList<Company> company_arr;
Placement_Office(){
placedstudents_arr = new ArrayList<Student>();
ongoingplacements_arr = new ArrayList<Student>();
students_arr = new ArrayList<Student>();
company_arr = new ArrayList<Company>();
}
public void add_student(Student std){
ongoingplacements_arr.add(std);
students_arr.add(std);
}
public void add_company(Company comp){
company_arr.add(comp);
}
public ArrayList<Student> getongoingplacements_arr(){
return ongoingplacements_arr;
}
public ArrayList<Company> getcompany_arr(){
return company_arr;
}
public void show_details(int roll){
for(int i=0;i<students_arr.size();i++){
if(students_arr.get(i).getroll()==roll){
students_arr.get(i).show_student_details();
}
}
}
public void getcompanydetail(String name){
for(int i=0;i<company_arr.size();i++){
if(company_arr.get(i).getcompany_name().equals(name)){
company_arr.get(i).show_company_details();
}
}
}
public void select_students(String company){
System.out.println("Roll Number of selected Students : ");
int[][] techincalscores;
int total_students;
int number_of_required_students;
int max=-1;
int count;
int test=-2;
int test1=-2;
boolean jkl=true;
boolean ghj=true;
float maxgpa;
int select=-1;
ArrayList<Student> scores = new ArrayList<Student>();
for(int k=0;k<company_arr.size();k++){
if(company_arr.get(k).getcompany_name().equals(company)){
techincalscores=company_arr.get(k).gettechnicalscores();
number_of_required_students=company_arr.get(k).getnumber_of_required_students();
total_students=company_arr.get(k).gettotal_students();
while(number_of_required_students>0){
max=-1;
test=-2;
test1=-2;
ghj=true;
jkl=true;
select=0;
maxgpa=0;
count=0;
for(int j=0;j<total_students;j++){
if(techincalscores[1][j]!=0){
if(max<techincalscores[1][j]){
max=techincalscores[1][j];
select=j+1;
}
}
}
for(int j=0;j<total_students;j++){
if(techincalscores[1][j]==max){
count++;
}
}
if(count==1){
System.out.println(select);
techincalscores[1][select-1]=0;
for(int i=0;i<ongoingplacements_arr.size();i++){
if(ongoingplacements_arr.get(i).getroll()==select && jkl==true){
placedstudents_arr.add(ongoingplacements_arr.get(i));
test1=i;
jkl=false;
break;
}
}
ongoingplacements_arr.remove(test1);
}
else{
for(int i=0;i<total_students;i++){
if(techincalscores[1][i]==max){
for(int j=0;j<ongoingplacements_arr.size();j++){
if(ongoingplacements_arr.get(j).getroll()==i+1){
maxgpa=Math.max(maxgpa,ongoingplacements_arr.get(j).getgpa());
}
}
}
}
for(int i=0;i<ongoingplacements_arr.size();i++){
if(ongoingplacements_arr.get(i).getgpa()==maxgpa){
System.out.println(ongoingplacements_arr.get(i).getroll());
select=ongoingplacements_arr.get(i).getroll()+1;
}
for(int l=0;l<ongoingplacements_arr.size();l++){
if(ongoingplacements_arr.get(l).getroll()==select && ghj==true){
placedstudents_arr.add(ongoingplacements_arr.get(l));
ghj=false;
test=l;
break;
}
}
}
ongoingplacements_arr.remove(test);
}
number_of_required_students--;
}
for(int g=0;g<company_arr.size();g++){
if(company_arr.get(g).getcompany_name().equals(company)){
company_arr.get(g).setapplicationstatus();
}
}
}
}
}
public void check_technical_result_all(int roll){
int[][] techincalscores;
boolean asd=true;
for(int i=0;i<placedstudents_arr.size();i++){
if(placedstudents_arr.get(i).getroll()==roll){
asd=false;
}
}
if(asd){
for(int i=0;i<company_arr.size();i++){
techincalscores=company_arr.get(i).gettechnicalscores();
if(techincalscores[1][roll-1]!=0){
System.out.println(company_arr.get(i).getcompany_name()+" "+techincalscores[1][roll-1]);
}
}
}
else{
System.out.println("No student with the given roll no has account");
}
}
public void check_qualified_Students(Company comp){
int[][] techincalscores;
Scanner abc = new Scanner(System.in);
for(int i=0;i<students_arr.size();i++){
for(int j=0;j<comp.geteligiblecourses_arr().size();j++){
if(students_arr.get(i).getbranch().equals(comp.geteligiblecourses_arr().get(j))){
System.out.print("Enter the score for Roll no. "+students_arr.get(i).getroll()+" ");
techincalscores=comp.gettechnicalscores();
techincalscores[1][students_arr.get(i).getroll()-1]=abc.nextInt();
}
}
}
}
public void check_open_companies(){
for(int i=0;i<company_arr.size();i++){
if(company_arr.get(i).getapplication_status().equals("OPEN")){
System.out.println(company_arr.get(i).getcompany_name());
}
}
}
public void all_removed(){
System.out.println("Accounts removed for :");
for(int i=0;i<placedstudents_arr.size();i++){
System.out.println(placedstudents_arr.get(i).getroll());
}
}
public void all_companyclosed(){
int test=-2;
System.out.println("Accounts removed for :");
for(int i=0;i<company_arr.size();i++){
if(company_arr.get(i).getapplication_status().equals("CLOSED")){
System.out.println(company_arr.get(i).getcompany_name());
test=i;
}
}
company_arr.remove(test);
System.out.println(company_arr.size());
// Iterator<Company> itr = company_arr.iterator();
// while(itr.hasNext()){
// Company co = itr.next();
// if(co.getapplication_status().equals("CLOSED")){
// company_arr.remove(co);
// }
// }
}
}
public class LA1{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int number_of_students=scan.nextInt();
Placement_Office ploff = new Placement_Office();
String company_name;
int number_of_eligible_courses;
ArrayList<String> eligiblecourses_arr = new ArrayList<String>();
int number_of_required_students;
for(int i=0;i<number_of_students;i++){
Student std = new Student(i+1,scan.nextFloat(),scan.next(),"Not Placed");
ploff.add_student(std);
}
System.out.println("----students registered----");
while(ploff.getongoingplacements_arr().size()>0 || ploff.getcompany_arr().size()>0){
switch(scan.nextInt()){
case 1:
company_name=scan.next();
System.out.print("Number of eligible courses : ");
number_of_eligible_courses=scan.nextInt();
for(int i=0;i<number_of_eligible_courses;i++){
eligiblecourses_arr.add(scan.next());
}
System.out.print("Number of required students : ");
number_of_required_students=scan.nextInt();
Company comp = new Company(company_name,number_of_eligible_courses,eligiblecourses_arr,number_of_required_students,number_of_students);
ploff.add_company(comp);
comp.show_company_details();
System.out.println("Enter the score for technical rounds");
ploff.check_qualified_Students(comp);
break;
case 2:
ploff.all_removed();
break;
case 3:
ploff.all_companyclosed();
break;
case 4:
System.out.println(ploff.getongoingplacements_arr().size()+" students left.");
break;
case 5:
ploff.check_open_companies();
break;
case 6:
ploff.select_students(scan.next());
break;
case 7:
ploff.getcompanydetail(scan.next());
break;
case 8:
ploff.show_details(scan.nextInt());
break;
case 9:
ploff.check_technical_result_all(scan.nextInt());
break;
default:
System.out.println("Inavlid option, please try again.");
break;
}
}
}
}