-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPA_1_CourseProblem.java
More file actions
120 lines (99 loc) · 2.96 KB
/
IPA_1_CourseProblem.java
File metadata and controls
120 lines (99 loc) · 2.96 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
import java.util.*;
class course {
private int courseId;
private String courseName;
private String courseAdmin;
private int quiz;
private int handson;
public course(int courseId, String courseName, String courseAdmin, int quiz, int handson) {
this.courseId = courseId;
this.courseName = courseName;
this.courseAdmin = courseAdmin;
this.quiz = quiz;
this.handson = handson;
}
public int getcourseId() {
return courseId;
}
public String getcourseName() {
return courseName;
}
public String getcourseAdmin() {
return courseAdmin;
}
public int getquiz() {
return quiz;
}
public int gethandson() {
return handson;
}
}
public class IPA_1_CourseProblem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
course[] arr = new course[4];
for (int i = 0; i < 4; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();
int e = sc.nextInt();
sc.nextLine();
arr[i] = new course(a, b, c, d, e);
}
String value = sc.nextLine();
int val = sc.nextInt();
int ans1 = findAvgOfQuizByAdmin(arr, value);
if (ans1 > 0) {
System.out.println(ans1);
} else {
System.out.println("No Course found");
}
course[] ans2 = sortCourseByHandsOn(arr, val);
if (ans2 != null && ans2.length > 0) {
for (course c : ans2) {
System.out.println(c.getcourseName());
}
} else {
System.out.println("No Course found with mentioned attribute.");
}
sc.close();
}
public static int findAvgOfQuizByAdmin(course[] arr, String value) {
int total = 0;
int count = 0;
for (course c : arr) {
if (c.getcourseAdmin().equalsIgnoreCase(value)) {
total += c.getquiz();
count++;
}
}
if (count>0){
return total/count;
}
return 0;
}
public static course[] sortCourseByHandsOn(course[] arr, int limit) {
TreeMap<Integer, List<course>> map = new TreeMap<>();
int totalCount = 0;
for (course c : arr) {
if (c.gethandson() < limit) {
map.putIfAbsent(c.gethandson(), new ArrayList<>());
map.get(c.gethandson()).add(c);
totalCount++;
}
}
if (totalCount == 0) {
return null;
}
course[] result = new course[totalCount];
int index = 0;
for (Map.Entry<Integer, List<course>> entry : map.entrySet()) {
for (course c : entry.getValue()) {
result[index++] = c;
}
}
return result;
}
}