- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentsMarkAnalyzer.java
More file actions
Latest commit
94 lines (73 loc) · 2.7 KB
/
Copy pathStudentsMarkAnalyzer.java
File metadata and controls
94 lines (73 loc) · 2.7 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
packagecom.sarvesh.javabasics;
importjava.util.Scanner;
publicclassStudentsMarkAnalyzer {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
System.out.print("Enter Number of Students : ");
intnumberOfStudents = sc.nextInt();
double[] marksOfStudents = newdouble[numberOfStudents];
if (numberOfStudents <= 0) {
System.out.println("Try Again , Number of students can't be zero.");
}
System.out.print("Enter Student's Marks : ");
for(inti =0;i<numberOfStudents;i++) {
marksOfStudents[i] = sc.nextInt();
}
doubletotal = calculateTotal(marksOfStudents);
doubleaverage = calculateAverage(total, numberOfStudents);
inthighestIndex = findHighestIndex(marksOfStudents);
intlowestIndex = findLowestIndex(marksOfStudents);
intaboveAverageCount = countAboveAverage(marksOfStudents, average);
printReport(total, average, marksOfStudents, highestIndex, lowestIndex, aboveAverageCount);
sc.close();
}
publicstaticdoublecalculateTotal(double[] marks) {
doubletotal = 0;
for (doublemark : marks) {
total += mark;
}
returntotal;
}
publicstaticdoublecalculateAverage(doubletotal, intcount) {
returntotal / count;
}
publicstaticintfindHighestIndex(double[] marks) {
doublemax = marks[0];
intindex = 0;
for (inti = 1; i < marks.length; i++) {
if (marks[i] > max) {
max = marks[i];
index = i;
}
}
returnindex;
}
publicstaticintfindLowestIndex(double[] marks) {
doublemin = marks[0];
intindex = 0;
for (inti = 1; i < marks.length; i++) {
if (marks[i] < min) {
min = marks[i];
index = i;
}
}
returnindex;
}
publicstaticintcountAboveAverage(double[] marks, doubleaverage) {
intcount = 0;
for (doublemark : marks) {
if (mark > average) {
count++;
}
}
returncount;
}
publicstaticvoidprintReport(doubletotal, doubleaverage, double[] marks, inthighestIndex, intlowestIndex, intaboveAverageCount) {
System.out.println("\n===== REPORT =====");
System.out.printf("Total Marks: %.2f%n", total);
System.out.printf("Average Marks: %.2f%n", average);
System.out.printf("Highest Marks: %.2f (Index %d)%n", marks[highestIndex], highestIndex);
System.out.printf("Lowest Marks: %.2f (Index %d)%n", marks[lowestIndex], lowestIndex);
System.out.printf("Students Above Average: %d%n", aboveAverageCount);
}
}