-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grader.java
43 lines (33 loc) · 969 Bytes
/
Grader.java
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
public class Grader {
private double[] testScores;
public Grader(double[] scoreArray) {
testScores = scoreArray;
}
public double getLowestScore() {
double lowest;
lowest = testScores[0];
for (int index = 1; index < testScores.length; index++) {
if (testScores[index] < lowest) {
lowest = testScores[index];
}
}
return lowest;
}
public double getAverage() {
double total = 0;
double lowest;
double average;
if (testScores.length < 2) {
System.out.println("ERROR: You must have at least two test scores!");
average = 0;
} else {
for (double score : testScores){
total += score;
}
lowest = getLowestScore();
total -= lowest;
average = total / (testScores.length - 1);
}
return average;
}
}