I have created 2 methods.One to import a file and 2 to get scores for each student by using the data and comparing it against the answer key. Although the methods work fine independantly I have struggled to make them work together.Any suggestions/help?
here are the methods. I have tried parsing from data
String to int t compare with the answer key and vice versa and numerous other thing but to no avail. Please help if possible.
First part of code to test for scoring final int T = 1;
final int F = 0;
int[] userAnswers = {80,F,T,F,F,T,F,F,T,F,T};
int[] answerKey = {F,T,F,F,T,F,F,T,F,T};
int userScore = 0;
System.out.println("ID="+userAnswers[0]);
for (int i=0; i<answerKey.length; i++) {
if (userAnswers[i+1] == answerKey) {
userScore++);
}
}
System.out.println(userScore++);
}
}
import java.io.*;
import javax.swing.JOptionPane;
2nd part of code to import data final int T = 1;
final int F = 0;
String[] students =new String[];
int[] answerKey = {F,T,F,F,T,F,F,T,F,T}; //Array answer key for scores processing
int userScore = 0;
public void enterStudentInfo()
{
try {
// Create object ins - the input file. FileReader inStream = new FileReader("a:/student.txt");
BufferedReader ins = new BufferedReader(inStream);
int i = 0;
for (int lineCount = 0; lineCount < 10; lineCount++) {
students[i] = ins.readLine();
System.out.println(students); //Test if the data comes in
}
}
catch (IOException ex) {
System.out.println("i/o error: " + ex.getMessage());
ex.printStackTrace();
}
catch (NumberFormatException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}