Java Reference
In-Depth Information
28Gets the average of the added data.
29 @return
the average or 0 if no data has been added
30 */
31 public double getAverage()
32 {
33 if (count == 0) return 0;
34 else return sum / count;
35 }
36
37 /**
38Gets the largest of the added data.
39 @return
the maximum or 0 if no data has been
added
40 */
41 public double getMaximum()
42 {
43 return maximum;
44 }
45
46 private double sum;
47 private double maximum;
48 private int count;
49 }
Output
Enter value, Q to quit: 10
Enter value, Q to quit: 0
Enter value, Q to quit: -1
Enter value, Q to quit: Q
Average = 3.0
Maximum = 10.0
249
250
S
ELF
C
HECK
7.
Why does the
DataAnalyzer
class call
in.next
and not
in.nextDouble
?
8.
Would the
DataSet
class still compute the correct maximum if you
simplified the update of the
maximum
field in the
add
method to the
following statement?