-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode 41.txt
94 lines (50 loc) · 1.5 KB
/
code 41.txt
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
package testscorestatistics;
import javax.swing.JOptionPane;
public class TestScoreStatistics{
static int intHigh, intLow;
public static void main (String[] args){
int intScore;
int intSum;
int intCount;
double dblAverage;
String strScore;
intSum = 0;
intCount = 0;
intHigh = -1;
intLow = 200;
strScore = JOptionPane.showInputDialog(null, "Enter score (999 to exit)");
intScore = Integer.parseInt(strScore);
while (intScore != 999){
if ((intScore < 0) || (intScore > 100)){
JOptionPane.showMessageDialog(null, "Invalid score entered");
}
else{
// average stuff
intSum = intSum + intScore;
intCount = intCount + 1;
// high
intHigh = High(intScore);
// low
intLow = Low(intScore);
}
strScore = JOptionPane.showInputDialog(null, "Enter score (999 to exit)");
intScore = Integer.parseInt(strScore);
}
dblAverage = intSum / intCount;
JOptionPane.showMessageDialog(null, "The average score of " + intCount + " students is " + dblAverage + "\n" +
"The highest score is " + intHigh + "\n" +
"The lowest score is " + intLow );
}
public static int High(int intNumber){
if (intNumber > intHigh)
return intNumber;
else
return intHigh;
}
public static int Low(int intNumber){
if (intNumber < intLow)
return intNumber;
else
return intLow;
}
}