/*
* Write an application that reads daily temperatures for 12 months and allows
* the user to get statistics. Support at least three options: monthly average
* of a given month, yearly average, and lowest and highest temperatures of a
* given month. Use a text file to store temperatures. A line in the text file
* contains daily temperatures for one month. The first line in the text file
* contains temperatures for January; the second line, those for February; and
* so forth. Using StringTokenizer to parse a line into temperatures of type
* float. For a data structure, consider using either an array of Month or a
* two-dimensional array of float. Month is a class you define yourself.
*/
import java.io.*;
import java.util.*;
import java.text.*;
class homeWork6{
public static void main( String[] args) throws IOException{
File inFile = new File("templog.txt");
FileReader fileReader = new FileReader(inFile);
BufferedReader bufReader = new BufferedReader(fileReader);
DecimalFormat df = new DecimalFormat("0.00");
for(int i = 0;i < 12; i++){
String str = bufReader.readLine();
StringTokenizer parser = new StringTokenizer(str);
int count = 0;
float[] days = new float[31];
while(parser.hasMoreTokens()){
//System.out.println(parser.nextToken());
String next = parser.nextToken();
//System.out.println(next);
float newvar = Float.parseFloat(next);
//System.out.println(newvar);
days [count]= newvar;
count++;
}
float monthlyAverage;
float sum = 0;
for(int j = 0; j < 31; j++){
//System.out.println(days[j] + " Sum is: " + df.format(sum));
sum += days[j];
//System.out.println("Sum is: " + sum);
}
monthlyAverage = sum / 31;
//System.out.println("Sum is: " + df.format(sum) + " || " + "Monthly Average is: " + df.format(monthlyAverage));
//System.out.println("");
}
bufReader.close();
}
}