I'm having trouble printing out what I want. If I put my printing statements inside the Calculate method, it does print out what I expect. However, I want to do it in a separate method. Can anyone tell me what I did wrong? Also, can anyone point out to me if I have any unnecessary codes?(meaning if I take them out, it still wouldn't affect the outcome.) Thanks in advance.
import java.util.Scanner;
import java.io.File;
//import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.*;
public class Proj11852
{
private static boolean DEBUG= false;
public static void main(String[]args)throws IOException
{
int [] Years = new int[50];
double[] Population = new double[50];
int LargeYear1=0;
int LargeYear2=0;
double CurrentPercent=0;
double LargestPercent=0;
int Size= (Population.length) -1;
InputData(Years, Population, args[0]);
if (DEBUG) printArrays(Years,Population,Size);
Calculate(Years, Population,Size, CurrentPercent, LargestPercent, LargeYear1, LargeYear2);
PrintResult(LargestPercent, LargeYear1, LargeYear2);
}
private static int InputData(int[]Years, double[]Population, String filename)throws IOException
{
Scanner s = new Scanner (new File(filename));
int counter=0;
while(s.hasNext())
{
Years[counter]= s.nextInt();
Population[counter]= s.nextInt();
counter++;
}
s.close();
return counter;
}
public static void Calculate(int [] Years, double [] Population, int Size, double CurrentPercent, double LargestPercent, int LargeYear1, int LargeYear2)throws IOException
{
int counter=0;
while (counter<Size)
{
CurrentPercent= (((Population[counter+1])/(Population[counter]))-1)*100;
if (CurrentPercent>LargestPercent)
{
LargestPercent=CurrentPercent;
LargeYear1= Years[counter];
LargeYear2= Years[counter+1];
}
counter++;
}
}
private static void PrintResult(double LargestPercent, int LargeYear1, int LargeYear2)throws IOException
{
DecimalFormat df = new DecimalFormat("00.00");
System.out.println(LargeYear1+ ", "+ LargeYear2+ ": "+ df.format(LargestPercent));
}
private static void printArrays(int [] Years, double [] Population, int Size)
{
for (int i=0 ; i<Size; i++)
{
System.out.print(Years[i]+ " ");
System.out.println(Population[i]);
}
}
}