I'm having a problem with a Java assignment. We are using arrays to store test grades and compare them to an answer key, also stored in an array. The input file is organized so that the first line contains the the correct answers. Each following...
<div>I'm having a problem with a Java assignment. We are using arrays to store test grades and compare them to an answer key, also stored in an array. The input file is organized so that the first line contains the the correct answers. Each following line contains the students ID a white space, then their test answers. If the question was not answered, a whitespace apears in place of T or F.
I am able to read the first line of the input file and fill the answerKey array, but when I try to start pulling in the ID's and Responces, I get a <font size="2"><font color="#000080">
java.util.NoSuchElementException. The following code is what I have so far and includes a loop for testing.<font color="#000080">
package chapter9;
import java.util.*;
import java.io.*;
public class RunApp9 {
public static void main(String[] args) throws
FileNotFoundException,IOException
{
Scanner inFile =
new Scanner(new FileReader ("h:\\Game Developement 1\\workspace\\GameDesign1\\src\\chapter9\\Ch9_Ex6D ata.txt"));
PrintWriter outFile =
new PrintWriter("h:\\Game Developement 1\\workspace\\GameDesign1\\src\\chapter9\\test2.tx t");
String key = inFile.next();
int testLength = key.length();
char[] answerKey = new char[testLength];
for (int i = 0; i < testLength; i++)
{
answerKey[i] = key.charAt(i);
}
String[][] responces = new String[4][2];
for (int i = 0; i < responces.length;i++)
{
for (int j = 0;j < responces[i].length;j++)
{
responces[i][j] = "";
}
}
while(inFile.hasNext())
{
for (int i = 0; i < responces.length;i++)
{
for (int j = 0;j < responces[i].length;j++)
{
<font size="2">responces[0][i]= inFile.next(); //<b><font color="red">