Hi, I'm working on a project where I have two classes, Divisions and SalesStats. I need to read in a text file from a method in SalesStats and store that data into two dimensional arrays to Divisions. When I execute, only 0.0 is coming out and not the numbers from
the text file. Can someone help me/guide me to what I'm doing wrong?
DIVISION 1
Quarter 1 :
0.0
Quarter 2 :
0.0
Quarter 3 :
0.0
Quarter 4 :
0.0
public class Divisions
{
public final int DIVISION = 6;
public final int QUARTERS = 4;
private static double[][] sales;
public static void setSales(int div, int qrt, double amount)
{
double[][] sales = new double[6][4]; // This might be the problem
amount = sales[div][qrt];
}
public static double getSales(int div, int qrt)
{
double[][] sales = new double[6][4]; // This might be the problem
return sales[div][qrt];
}
}
public class SalesStats
{
public static void main(String args[]) throws IOException
{
Divisions d = new Divisions();
readValues(d);
displaySales(d);
...
public static void readValues(Divisions d) throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter input filename: ");
String input = keyboard.nextLine();
File myfile = new File(input);
if (!myfile.exists())
{
System.out.println("input file " + input + " does not exist");
System.exit(0);
}
Scanner inputFile = new Scanner(myfile);
for (int i = 0; i < d.DIVISION; i++)
for (int j = 0; j < d.QUARTERS; j++)
{
Divisions.setSales(i,j,inputFile.nextDouble());
}
inputFile.close();
}
public static void displaySales(Divisions d)
{
...
for (int i = 0; i < d.DIVISION; i++)
{
System.out.println("DIVISION " + (i+1));
for (int j = 0; j < d.QUARTERS; j++)
{
System.out.println("Quarter " + (j+1) + " : ");
System.out.println(Divisions.getSales(i,j));
}
}
}
Thank you!