How can I read a String from a file split it into characters and put it in
to a 2D array?
I am creating a program that simulates the function of a scantron marker.
I have a text file with the name of the student follow by their answers.
Here's the sample file I created:
Arnie EADCC Betty dadec Carol ba ea
In my main I ask the user to input the file name and I pass that to a
QuizMarker class that I created. Now I want to grab the name as a string
and put it into a 1D array and grab the answers as a character array and
put it into a 2D array so that I can compare the Student answers with a
correct answers file. I hard coded the number of rows just for testing
purposes. I have been trying to figure out how to make this work the whole
freaking day but my brain is completely toasted by now. I need HELP. here
is my code for the method readNamesAnswers():
public void readNamesAnswers(){
while (readerStu_Ans.hasNext()){
studentName[indexStudentName] = readerStu_Ans.nextLine();
for (int iRowStudentAnswer=0; iRowStudentAnswer<3;
iRowStudentAnswer++){
studentAnswers[iRowStudentAnswer]=
stuAnswers.split("(?!^)");
System.out.println(studentAnswers[iRowStudentAnswer][0]);
}
for(int row=0; row<3; row++){
for(int column= 0;
column<studentAnswers[column].length; column++){
System.out.println(studentAnswers[column][row]);
}}
System.out.println("\n"+studentName[indexStudentName]);
System.out.println();
indexStudentName++;
}
}
PS. I new to java and programming in general. Thanks in advance for all
the help.
No comments:
Post a Comment