What's is wrong with the logic of the code? There're two methods: readAllExams creates and returns an array of the objects and also calls another method readExam which returns object. A passed Scanner object is a textfile which has 10 lines different people's names, ID, midterm or final, and score, for example: John McGregor 2 'F' 100. So what did I do wrong here? The method gives smth like this: [LExam;@717da562. Thanks in advance, folks!
public static void main(String [] args) throws FileNotFoundException
{
Scanner data = new Scanner(new File("Exam.txt"));
Exam[] tempObject = readAllExams(data);
System.out.println(tempObject);
}
public static Exam[] readAllExams(Scanner s) throws ArrayIndexOutOfBoundsException
{
readExam(s);
String firstName = "";
String lastName = "";
int ID = 0;
String examType = "";
int score = 0;
int index = 0;
Exam[] object = new Exam[50];
while(s.hasNext())
{
//Returns firtsName and lastName
firstName = s.next();
lastName = s.next();
//Returns ID number
if(s.hasNextInt())
{
ID = s.nextInt();
}
else
s.next();
//Returns examType which is 'M' or 'F'
examType = s.next();
if(s.hasNextInt())
{
score = s.nextInt();
}
object[index] = new Exam(firstName, lastName, ID, examType, score);
System.out.println();
index++;
}
return object;
}
public static Exam readExam(Scanner s)
{
String firstName = "";
String lastName = "";
int ID = 0;
String examType = "";
int score = 0;
while (s.hasNext())
{
//Returns firtsName and lastName
firstName = s.next();
lastName = s.next();
//Returns ID number
if(s.hasNextInt())
{
ID = s.nextInt();
}
else
s.next();
//Returns examType which is 'M' or 'F'
examType = s.next();
if(s.hasNextInt())
{
score = s.nextInt();
}
}
Exam temp = new Exam(firstName, lastName, ID, examType, score);
return temp;
}