im trying to get the same heat index that prints int the program to write to a file. i have copied the procedure from another program that worked correctly. any help is appreciated.
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;
import java.io.File;
public class HeatIndex
{
public static void main(String [] args) throws IOException
{
Scanner inFile = new Scanner(new File("BIRMINGHAM AP,AL temp record test.txt"));
double sumTemp = 0;
double averageTemp = 0;
double sumHumidity = 0;
double averageHumidity = 0;
double sumHeatIndex = 0;
double averageHeatIndex = 0;
int counter = 0;
PrintWriter outFile = new PrintWriter (new File("writeFile.txt"));
double bhamTemp[] = new double[12];
for (int bhamTempIndex = 0; bhamTempIndex <= 11;)
{
bhamTemp[bhamTempIndex] = inFile.nextDouble();
sumTemp += bhamTemp[bhamTempIndex];
averageTemp = sumTemp/12;
bhamTempIndex++;
}
Scanner inFile2 = new Scanner(new File("13876BIRMINGHAM AP,AL Humidity Record Test.txt"));
double bhamHumidity[] = new double [12];
for (int bhamHumidityIndex = 0; bhamHumidityIndex <= 11;)
{
bhamHumidity[bhamHumidityIndex] = inFile2.nextDouble();
sumHumidity += bhamHumidity[bhamHumidityIndex];
averageHumidity = sumHumidity/ 12;
bhamHumidityIndex++;
}
double heatIndex[] = new double [12];
for (int indexCounter = 0; indexCounter <= 11;)
{
heatIndex[indexCounter] = heatIndex[indexCounter] = -42.379 + (2.04901523 * bhamTemp[indexCounter]) + (10.14333127 * bhamHumidity[indexCounter]) - (.22475541 * bhamTemp[indexCounter] * bhamHumidity[indexCounter]) - (6.83783 * .001 * bhamTemp[indexCounter] * bhamTemp[indexCounter]) - (5.481717 * .01 * bhamHumidity[indexCounter] * bhamHumidity[indexCounter]) + (1.22874 * .001 * bhamTemp[indexCounter] * bhamTemp[indexCounter] * bhamHumidity[indexCounter]) + (8.5282 * .0001 * bhamTemp[indexCounter] * bhamHumidity[indexCounter] * bhamHumidity[indexCounter]) - (1.99 * .000001 * bhamTemp[indexCounter] * bhamTemp[indexCounter] * bhamHumidity[indexCounter] * bhamHumidity[indexCounter]);
sumHeatIndex += heatIndex[indexCounter];
averageHeatIndex = sumHeatIndex/12;
outFile.println(heatIndex[indexCounter]);
indexCounter++;
}
System.out.println(" Heat Index: Birmingham, AL");
System.out.println();
System.out.println(" Months");
System.out.println("\n");
System.out.println(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Avg");
System.out.println("*******************************************************************************************************************************************");
System.out.printf("Temp F %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f\n", bhamTemp[0],bhamTemp[1],bhamTemp[2],bhamTemp[3],bhamTemp[4],bhamTemp[5],bhamTemp[6],bhamTemp[7],bhamTemp[8],bhamTemp[9],bhamTemp[10],bhamTemp[11], averageTemp);
System.out.printf("Humidity %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f\n", bhamHumidity[0],bhamHumidity[1],bhamHumidity[2],bhamHumidity[3],bhamHumidity[4],bhamHumidity[5],bhamHumidity[6],bhamHumidity[7],bhamHumidity[8],bhamHumidity[9],bhamHumidity[10],bhamHumidity[11],averageHumidity);
System.out.printf("HI %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f\n", heatIndex[0],heatIndex[1],heatIndex[2],heatIndex[3],heatIndex[4],heatIndex[5],heatIndex[6],heatIndex[7],heatIndex[8],heatIndex[9],heatIndex[10],heatIndex[11], averageHeatIndex);
System.out.println("*******************************************************************************************************************************************");
}
}