0
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class HurricaneAnalysis {

  public static void parseData(File inputFile, File outputFile) throws FileNotFoundException {
      Scanner in = new Scanner(inputFile);

      int endYear = in.nextInt();
      int startYear = in.nextInt();
      int i = 0;

      final int NUM_ELEMENTS = (endYear-startYear);

      int[] yearNum = new int[NUM_ELEMENTS];
      int[] numStorms = new int[NUM_ELEMENTS];
      int[] numHurricanes = new int[NUM_ELEMENTS];
      int[] damageCost = new int[NUM_ELEMENTS];

      while(in.hasNextLine()) {

         String[] inputData = in.nextLine().split("/t");
         yearNum[i] = Integer.parseInt(inputData[0]);
         numStorms[i] = Integer.parseInt(inputData[1]);
         numHurricanes[i] = Integer.parseInt(inputData[2]);
         damageCost[i] = Integer.parseInt(inputData[3]);

         i++; 

         in.close();
      }

      calculateAverage (numStorms);
      calculateAverage (numHurricanes);
      calculateAverage (damageCost);
      findHighest (numStorms, yearNum);
      findHighest (numHurricanes, yearNum);  
    }


  public static double calculateAverage (int[] data) {

      int numSum = 0;
      int i;

      for (i=0; i < data.length; i++) {
        numSum += data[i]; //cast as double 
      }

      int avgNum = Math.round((numSum / data.length)*1000)/1000;

      return (double)avgNum;

      }



  public static String findHighest (int[] storm, int[] year) {

      int maxVal = storm[0];
      int i;
      int maxLoopNum = 0;

      for (i = 0; i < storm.length; ++i) {
          if (storm[i] > maxVal) {
              maxLoopNum = i;
          }
      }

      return "" + year[maxLoopNum];   
  }



  public static void main(String[] args) throws FileNotFoundException {


      File inFile = new File("/Desktop/project5Data.txt");

      File outFile = new File("/Desktop/HurricaneResults.txt");

      parseData(inFile, outFile);


    }
}

This is my code so far. When I run in Eclipse, I get a runtime errorRuntime Error

I am having trouble finding the problem, because my method parameters all match the variable types used in the methods, and I checked the variable output types and modified by parsing.

How should I identify where this error is occurring and what is it most likely resulting from?

Ryan
  • 1
  • 3

0 Answers0