-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCollege.java
More file actions
90 lines (78 loc) · 3.02 KB
/
College.java
File metadata and controls
90 lines (78 loc) · 3.02 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
package PackFATPrep;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
class VITFeedback implements Comparable<VITFeedback> {
String course_Name, faculty_Name;
int feedback_Rating;
void getMethod(Scanner scanner) {
course_Name = scanner.nextLine();
faculty_Name = scanner.nextLine();
feedback_Rating = scanner.nextInt();
}
public int compareTo(VITFeedback e) {
return this.feedback_Rating < e.feedback_Rating ? 1 : this.feedback_Rating > e.feedback_Rating ? -1 : 0;
}
}
public class College {
static double AverageRating(ArrayList<VITFeedback> students) {
Iterator<VITFeedback> iterator = students.iterator();
double total = 0;
int count = 0;
while (iterator.hasNext()) {
total += iterator.next().feedback_Rating;
count++;
}
return total / count;
}
static void View_All_Feedbacks(ArrayList<VITFeedback> students) {
Iterator<VITFeedback> iterator = students.iterator();
System.out.println("Course Name\t\tFaculty Name\t\tFeedback");
while (iterator.hasNext()) {
VITFeedback temp = iterator.next();
System.out.println(temp.course_Name + "\t\t" + temp.faculty_Name + "\t\t" + temp.feedback_Rating);
}
}
static void Get_Highest_Feedback(ArrayList<VITFeedback> students) {
Collections.sort(students);
Iterator<VITFeedback> iterator = students.iterator();
VITFeedback highest = iterator.next();
System.out.println("Course Name\t\tFaculty Name\t\tFeedback");
System.out.println(highest.course_Name + "\t\t" + highest.faculty_Name + "\t\t" + highest.feedback_Rating);
while (iterator.hasNext()) {
VITFeedback temp = iterator.next();
if (temp.feedback_Rating != highest.feedback_Rating) {
break;
}
System.out.println(temp.course_Name + "\t\t" + temp.faculty_Name + "\t\t" + temp.feedback_Rating);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<VITFeedback> students = new ArrayList<VITFeedback>();
System.out.print("Number of students: ");
final int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
VITFeedback temp = new VITFeedback();
temp.getMethod(scanner);
students.add(temp);
}
System.out.print("Enter Choice: ");
switch (scanner.nextInt()) {
case 1:
AverageRating(students);
break;
case 2:
View_All_Feedbacks(students);
break;
case 3:
Get_Highest_Feedback(students);
break;
default:
break;
}
scanner.close();
}
system.out.println(" The program ends here");
}