import java.awt.*;
import hsa.Console;
import java.io.*;
import java.util.*;
import java.text.*;
public class P1_3_7
{
static Console c;
static double[] pop97;
static double[] pop01;
static double[] expPopArray;
public static void main (String[] args)
{
c = new Console (28, 80);
String cities[] = {"Toronto", "Montr?al", "Ottawa-Hull", "Calgary", "Edmonton", "Calgary", "Qu?bec", "Winnipeg", "Hamilton", "London", "Kitchener",
"St. Catharines-Niagara", "Halifax", "Victoria", "Windsor", "Oshawa", "Saskatoon", "Regina", "St. John's", "Chicoutimi-Jonqui?re",
"Sudbury", "Sherbrooke", "Trois-Rivi?res", "Thunder Bay", "Saint John"};
c.print ("Enter a year greater than 2000: ");
int year = c.readInt ();
int yearDiff = year - 1997;
c.clear ();
c.println ("Top ten expected populations for the year " + year + " are (in thousands): \n");
for (int i = 0 ; i < 25 ; i++)
{
try
{
BufferedReader br = new BufferedReader (new FileReader (new File ("popCities97to01.txt")));
pop97 = new double [25];
pop01 = new double [25];
String line = "";
for (int j = 0 ; j <= 24 ; j++)
{
line = br.readLine ();
pop97 [j] = Double.parseDouble (line.substring (0, 9));
pop01 [j] = Double.parseDouble (line.substring (12, 21));
}
br.close ();
}
catch (IOException e)
{
c.print ("File not found.");
}
double diff = pop01 [i] - pop97 [i];
double pop = pop97 [i];
double factor = Math.pow (1.0 + diff / pop, 1 / 4.0);
double expPop = (pop * (Math.pow (factor, yearDiff)));
expPopArray = new double [25];
expPopArray [i] = expPop;
// c.println(expPopArray[i]); // If I try to print the array from here it works
}
c.print (expPopArray [2]); // If I try to print the array from here it just returns 0
}
}
|