I have written a class to read a text file and write the data into a
2D array of max records x 12 fields. Now that I have this working, I need
to be ablel to call this array from my other classes to perform different
tasks on the data. Here is the code from the main class:
// Open the file to read
File file = new File(filename);
Scanner input = new Scanner(file);
// create a Vehicle Records Array of
// Rows [Max Records] x Columns [12]
final int MAX = number++;
String[][] VehicleData = new String[MAX][12];
// read data from a file
while (input.hasNext() & (i <= MAX))
{
VehicleData[i][0] = input.next(); // Vehicle type
VehicleData[i][1] = input.next(); // Driver last name field
VehicleData[i][2] = input.next(); // Street address
VehicleData[i][3] = input.next(); // City
VehicleData[i][4] = input.next(); // State
VehicleData[i][5] = input.next(); // Zip Code
VehicleData[i][6] = input.next(); // Student ID
VehicleData[i][7] = input.next(); // Car Make
VehicleData[i][8] = input.next(); // Car Model
VehicleData[i][9] = input.next(); // Car Year
VehicleData[i][10] = input.next(); // Car VIN
VehicleData[i][11] = input.next(); // State of car registration
i++;
}
// Close the file
input.close();
// The getData method accepts an array as an argument
public static void getData(String[][] array)
{
return VehicleData;
}
obviously something is wrong with my method to pass the array but I am a little lost!
Any and all help will be greatly appreciated!
Thanks!
Debi