Reset your count at each new line
...
while (inputStream.hasNext()) {
count = 0;
...
It looks like you also have your math reversed for the first and last...
lastWeight-firstWeight
should probably be
firstWeight-lastWeight
Question
so i need to input a file with data like this
Joe Schmoe
76.5 20 30 25 10 75.9
Jilly Momilly Schmill
50.5 30 30 35 37 28 32 35 34 34 49.2
Gail Quail
62.3 15 17 10 3 10 63.6
Frank Crank
83.2 5 83.2
John Quann
57.9 30 32 35 32 30 57.2
i need the program to read the data and summarize it for each person example for Joe Schmoe out put would be
4 85 21.25 0.5999999999999943
which is the number of days (ints), total mins (sum of ints), average mins per day sum/days, and the final value is the first double minus the second.
my algorithm for reading the data is:
public void summaryData()
{
try
{
while (inputStream.hasNext())
{
line = inputStream.nextLine();
firstWeight = inputStream.nextDouble();
while (inputStream.hasNextInt())
{
sum += inputStream.nextInt();
count ++;
avg = (sum/count);
}
lastWeight = inputStream.nextDouble();
outputStream.println(count + " " + sum + " " + avg + " " + (lastWeight-firstWeight));
if(inputStream.hasNext())
inputStream.nextLine();
}
}
catch (InputMismatchException e)
{
System.out.print(e);
System.exit(0);
}
}
my problem is this i need the int count and the sum for each individual to start over rather than adding them all together.
any help or suggestions are greatly appreciated
sample output:
4 85 21.0 -0.5999999999999943
13 380 29.0 -1.2999999999999972
18 435 24.0 1.3000000000000043
19 440 23.0 0.0
24 599 24.0 -0.6999999999999957
Solution
Reset your count at each new line
...
while (inputStream.hasNext()) {
count = 0;
...
It looks like you also have your math reversed for the first and last...
lastWeight-firstWeight
should probably be
firstWeight-lastWeight