-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformanceAnalyzer.java
More file actions
67 lines (51 loc) · 1.73 KB
/
PerformanceAnalyzer.java
File metadata and controls
67 lines (51 loc) · 1.73 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
package com.sarvesh.javabasics;
import java.util.Scanner;
public class PerformanceAnalyzer {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of days: ");
int n = sc.nextInt();
if (n <= 0) {
System.out.println("Invalid input. Number of days must be positive.");
return;
}
double[] scores = new double[n];
System.out.println("Enter daily scores:");
for (int i = 0; i < n; i++) {
scores[i] = sc.nextDouble();
}
analyzePerformance(scores);
sc.close();
}
public static void analyzePerformance(double[] scores) {
double total = 0;
double max = scores[0];
double min = scores[0];
int maxIndex = 0;
int minIndex = 0;
for (int i = 0; i < scores.length; i++) {
total += scores[i];
if (scores[i] > max) {
max = scores[i];
maxIndex = i;
}
if (scores[i]<min) {
min = scores[i];
minIndex = i;
}
}
double average = total/scores.length;
int aboveAverageCount = 0;
for (double score : scores) {
if (score>average) {
aboveAverageCount++;
}
}
System.out.printf("Total Score: %.2f%n", total);
System.out.printf("Average Score: %.2f%n", average);
System.out.printf("Highest Score: %.2f (Day %d)%n", max, maxIndex);
System.out.printf("Lowest Score: %.2f (Day %d)%n", min, minIndex);
System.out.printf("Days Above Average: %d%n", aboveAverageCount);
}
}