Hi all - I am having a little trouble getting going on the methods for this assignment. I need to use a method which passes a Scanner as the object to create an array that is the correct size, but has null values. It reads in a file which contains a number on a single line at the top, which is the number of Student objects that are on the list. The Student objects themselves are first name, last name, followed by three test scroes. I am new to Java and am struggling on getting this going and am looking for any advice. The method must only return an array of correct size but with null values..as other methods will be used to populate the array. For example, if the number on the first line is three, it needs to create an array with fifteen null "slots".
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ProgrammingAssignment {
public static void main(String[] args) {
Student[] studentArray = null;
Scanner sc = new Scanner(System.in);
Scanner readFile = null;
String fileName = "";
boolean done = false;
int tries = 1;
File file = null;
while (!done) {
try {
System.out.println("Please enter the name of the file: ");
fileName = sc.nextLine();
file = new File(fileName);
readFile = new Scanner(file);
System.out.println(file);
done = true;
}
catch (FileNotFoundException fnfe) {
System.out.println("File not found");
if (tries == 3) {
System.out.println("Maximum tries exceeded.");
System.exit(1);
}
tries++;
}
}
sc.close();
readFile.close();
}
//creates and returns an uninitialized array of Student instances
//the returned array will be of the right size but each "slot" will
//have null values.
//needs to read the first line of the input file.
public static Student[] createStudentArray(Scanner sc) {
}