-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstitutionProblem.java
More file actions
105 lines (86 loc) · 2.86 KB
/
InstitutionProblem.java
File metadata and controls
105 lines (86 loc) · 2.86 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
import java.util.*;
class Institution{
int institutionId;
String institutionName;
int noOfStudentsPlaces;
int noOfStudentsCleared;
String location;
String grade;
public Institution(int institutionId , String institutionName, int noOfStudentsPlaces , int noOfStudentsCleared, String location ){
this. institutionId = institutionId;
this.institutionName = institutionName;
this.noOfStudentsPlaces = noOfStudentsPlaces;
this.noOfStudentsCleared = noOfStudentsCleared;
this.location = location;
}
public int getInstitutionId(){
return institutionId;
}
public String getInstitutionName(){
return institutionName;
}
public int getNoOfStudentsPlaces(){
return noOfStudentsPlaces;
}
public int getNoOfStudentsCleared(){
return noOfStudentsCleared;
}
public String getLocation(){
return location;
}
public String getGrade(){
return grade;
}
public void setGrade(String grade){
this.grade = grade;
}
}
public class InstitutionProblem {
public static void main (String[]args){
Scanner sc = new Scanner(System.in);
Institution[]arr = new Institution[4];
for(int i =0; i<arr.length; i++){
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
int d = sc.nextInt();
sc.nextLine();
String e = sc.nextLine();
arr[i] = new Institution(a,b,c,d,e);
}
String location = sc.nextLine();
String institutionName = sc.nextLine();
int sum = FindNumClearancedByLoc(arr,location);
System.out.println(sum);
Institution institute = UpdateInstitutionGrade(arr, institutionName);
if(institute!=null){
System.out.println(institute.institutionName+ ":" + institute.grade);
}else{
System.out.println("No Institute is available with the specified name");
}
}
public static int FindNumClearancedByLoc(Institution[]arr , String location){
int sum =0;
for(int i =0;i<arr.length; i++){
if(arr[i].location.equalsIgnoreCase(location)){
sum+=arr[i].noOfStudentsCleared;
}
}
return sum;
}
public static Institution UpdateInstitutionGrade(Institution[]arr, String institutionName){
for(int i =0; i<arr.length; i++){
if(arr[i].institutionName.equalsIgnoreCase(institutionName)){
int Rating=(arr[i].noOfStudentsPlaces * 100)/arr[i].noOfStudentsCleared;
if(Rating>=80){
arr[i].setGrade("A");
}else{
arr[i].setGrade("B");
}
return arr[i];
}
}
return null;
}
}