|
I don't know how to return a scanner object. See below a portion of my code.
CODE
public class MarkEntry {
public final int LEN = 200;
private String[] studNos; // Array for stroing student No's or ID's
private int[] studScores; // Array for storing the results
private int nStudents;
Scanner console = new Scanner(System.in);
public MarkEntry() {
int[] studScores = new int [LEN];
String[] studNos = new String [LEN];
nStudents = 0;
}
// This method repeatedly prompts user to enter a filename until user enters a valid filename.
// Once a valid filename is entered, this method returns a Scanner object created from the file.
// The parameter msg is used to construct the propmpt message by: "Enter " + msg + "filename: ".
// So if msg contains the string student list, then the prompt message would be: ?Enter student list filename:
Scanner getFileName(String msg)throws FileNotFoundException {
boolean valid = false;
Scanner scan = new Scanner (System.in);
String name = "";
while (true)
{
try {
System.out.print ("Enter file name: ");
System.out.flush();
name = scan.nextLine();
if (name == "student list")
name = "slist";
Scanner fin = new Scanner (new File(name));
break;
}
catch (FileNotFoundException e){
System.out.println("File not found try again:");
}
return
}
END CODE
The return statement above is my problem
|