processData
Category: Token-Based File Processing
Author: Stuart Reges
Book Chapter: 6.2
Problem: processData
Write a static method processData
that takes as a parameter a Scanner holding a sequence of integers and that
reports each of the cumulative sums of the sequence along with the average
of the numbers. For example, if the Scanner contains the following data:
8 4 2 9 7 13 5 9
your method should produce the following output:
Sum of 1 = 8
Sum of 2 = 12
Sum of 3 = 14
Sum of 4 = 23
Sum of 5 = 30
Sum of 6 = 43
Sum of 7 = 48
Sum of 8 = 57
Average = 7.125
Notice that the various lines of output report the sum including just the
first number, then including the first two numbers, then including the first
three numbers, and so on, up to the sum including all numbers. The final
line of output reports the average of the sequence of numbers. Notice that
this is the average of the numbers themselves, not the average of the
cumulative sums.
The amount of output will vary depending upon how many numbers are in the
sequence. For example, if the Scanner contains the following values:
1 2 3 4
the method should produce the following output:
Sum of 1 = 1
Sum of 2 = 3
Sum of 3 = 6
Sum of 4 = 10
Average = 2.5
You are to exactly reproduce the format of these sample outputs. You may
assume that the Scanner has at least one integer to be processed.
Write your solution to processData below.