Can somebody please help me with this code? I have the program correctly coded and operating properly, however, I forget how to write my output to a text file. Can somebody please help me here? Thanks.
/**
* This program calculates the monthly Heat Index for a specific city.
*
* @author John D. Barry
* @date January 30, 2009
*/
import java.util.Scanner;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
class HeatIndex
{
public static void main (String [ ] args) throws IOException
{
int index = 0;
double [] theTemps = new double[13];
File temps = new File("KeyWestTemp.txt");
Scanner inFile = new Scanner(temps);
while (inFile.hasNextDouble())
{
theTemps[index] = inFile.nextDouble();
index++;
}
for (double d: theTemps)
{
}
inFile.close();
System.out.println();
System.out.println();
index = 0;
double [] theHumidity = new double[12];
File humid = new File("KeyWestHumid.txt");
inFile = new Scanner(humid);
while (inFile.hasNextDouble())
{
theHumidity[index] = inFile.nextDouble();
index++;
}
for (double d: theHumidity)
{
}
int sumOne = 0;
for (int i = 0; i < theHumidity.length; i++)
{
sumOne += theHumidity[i];
}
double averageOne = sumOne / 12;
double fourthHI = (-42.379) + (2.04901523 * theTemps[4]) + (10.14333127 * theHumidity[4]) - (0.22475541 * theTemps[4] * theHumidity[4]) - (6.83783E-3 * theTemps[4] * theTemps[4]) - (5.481717E-2 * theHumidity[4] * theHumidity[4])+ (1.22874E-3 * theTemps[4] * theTemps[4] * theHumidity[4]) + (8.5282E-4 * theTemps[4] * theHumidity[4] * theHumidity[4]) - (1.99E-6 * theTemps[4] * theTemps[4] * theHumidity[4] * theHumidity[4]);
double fifthHI = (-42.379) + (2.04901523 * theTemps[5]) + (10.14333127 * theHumidity[5]) - (0.22475541 * theTemps[5] * theHumidity[5]) - (6.83783E-3 * theTemps[5] * theTemps[5]) - (5.481717E-2 * theHumidity[5] * theHumidity[5])+ (1.22874E-3 * theTemps[5] * theTemps[5] * theHumidity[5]) + (8.5282E-4 * theTemps[5] * theHumidity[5] * theHumidity[5]) - (1.99E-6 * theTemps[5] * theTemps[5] * theHumidity[5] * theHumidity[5]);
double sixthHI = (-42.379) + (2.04901523 * theTemps[6]) + (10.14333127 * theHumidity[6]) - (0.22475541 * theTemps[6] * theHumidity[6]) - (6.83783E-3 * theTemps[6] * theTemps[6]) - (5.481717E-2 * theHumidity[6] * theHumidity[6])+ (1.22874E-3 * theTemps[6] * theTemps[6] * theHumidity[6]) + (8.5282E-4 * theTemps[6] * theHumidity[6] * theHumidity[6]) - (1.99E-6 * theTemps[6] * theTemps[6] * theHumidity[6] * theHumidity[6]);
double seventhHI = (-42.379) + (2.04901523 * theTemps[7]) + (10.14333127 * theHumidity[7]) - (0.22475541 * theTemps[7] * theHumidity[7]) - (6.83783E-3 * theTemps[7] * theTemps[7]) - (5.481717E-2 * theHumidity[7] * theHumidity[7])+ (1.22874E-3 * theTemps[7] * theTemps[7] * theHumidity[7]) + (8.5282E-4 * theTemps[7] * theHumidity[7] * theHumidity[7]) - (1.99E-6 * theTemps[7] * theTemps[7] * theHumidity[7] * theHumidity[7]);
double eighthHI = (-42.379) + (2.04901523 * theTemps[8]) + (10.14333127 * theHumidity[8]) - (0.22475541 * theTemps[8] * theHumidity[8]) - (6.83783E-3 * theTemps[8] * theTemps[8]) - (5.481717E-2 * theHumidity[8] * theHumidity[8])+ (1.22874E-3 * theTemps[8] * theTemps[8] * theHumidity[8]) + (8.5282E-4 * theTemps[8] * theHumidity[8] * theHumidity[8]) - (1.99E-6 * theTemps[8] * theTemps[8] * theHumidity[8] * theHumidity[8]);
double ninthHI = (-42.379) + (2.04901523 * theTemps[9]) + (10.14333127 * theHumidity[9]) - (0.22475541 * theTemps[9] * theHumidity[9]) - (6.83783E-3 * theTemps[9] * theTemps[9]) - (5.481717E-2 * theHumidity[9] * theHumidity[9])+ (1.22874E-3 * theTemps[9] * theTemps[9] * theHumidity[9]) + (8.5282E-4 * theTemps[9] * theHumidity[9] * theHumidity[9]) - (1.99E-6 * theTemps[9] * theTemps[9] * theHumidity[9] * theHumidity[9]);
double sumTwo = theTemps[0] + theTemps[1] + theTemps[2] + theTemps[3] + fourthHI + fifthHI + sixthHI + seventhHI + eighthHI + ninthHI + theTemps[10] + theTemps[11];
double averageTwo = sumTwo / 12;
System.out.println(" Heat Index: Key West, Florida");
System.out.println();
System.out.println(" Months");
System.out.println(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Avg ");
System.out.println("***************************************************************************************************************************");
System.out.printf("Temp (F)%18.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f", theTemps[0],theTemps[1],theTemps[2],theTemps[3],theTemps[4],theTemps[5],theTemps[6],theTemps[7],theTemps[8],theTemps[9],theTemps[10],theTemps[11],theTemps[12]);
System.out.println();
System.out.printf("Humidity %17.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f%8.0f", theHumidity[0],theHumidity[1],theHumidity[2],theHumidity[3],theHumidity[4],theHumidity[5],theHumidity[6],theHumidity[7],theHumidity[8],theHumidity[9],theHumidity[10],theHumidity[11],averageOne);
System.out.println();
System.out.printf("HI (F)%20.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f%8.1f",theTemps[0],theTemps[1],theTemps[2],theTemps[3],fourthHI,fifthHI,sixthHI,seventhHI,eighthHI,ninthHI,theTemps[10],theTemps[11],averageTwo);
System.out.println();
inFile.close();
}
}