I just need the parsing done at the bottom of this code. Thanks. import java.io.
ID: 3529148 • Letter: I
Question
I just need the parsing done at the bottom of this code. Thanks.
import java.io.*;
import java.util.StringTokenizer;
public class Project {
private static FileInputStream inFile;
private static InputStreamReader inReader;
private static BufferedReader reader;
public static void main(String[] args) throws IOException
{
char[] testKey;
char[] studentLetterGrades = new char[127];
double[] studentNumberGrades = new double[127];
String[] studentIDs = new String[127]; // String[] to avoid need to pad IDs with preceding zeroes later on
initFile();
testKey = getKey();
String line;
int studentCount = 0;
while((line = reader.readLine()) != null)
{
StringTokenizer strTok = new StringTokenizer(line);
studentIDs[studentCount] = strTok.nextToken();
studentNumberGrades[studentCount] = parseAnswers(testKey, strTok.nextToken());
studentCount++;
}
}
public static void initFile() throws IOException
{
// Better to just include the file in the project; no changes to filename needed.
inFile = new FileInputStream ("data.txt");
inReader = new InputStreamReader(inFile);
reader = new BufferedReader(inReader);
}
public static char[] getKey() throws IOException
{
String line;
StringTokenizer strTkn;
line = reader.readLine();
strTkn = new StringTokenizer(line);
String answerKey = strTkn.nextToken();
return answerKey.toCharArray();
}
public static double parseAnswers(char[] key, String toCheck)
{
// Fill the method with your code
// Takes test answers key and token from StringTokenizer
// Return numeric grade for answers
return 0.0;
}
}
Explanation / Answer
import java.io.*; import java.util.StringTokenizer; public class Project { private static FileInputStream inFile; private static InputStreamReader inReader; private static BufferedReader reader; public static void main(String[] args) throws IOException { char[] testKey; char[] studentLetterGrades = new char[127]; double[] studentNumberGrades = new double[127]; String[] studentIDs = new String[127]; // String[] to avoid need to pad IDs with preceding zeroes later on initFile(); testKey = getKey(); String line; int studentCount = 0; while((line = reader.readLine()) != null) { StringTokenizer strTok = new StringTokenizer(line); studentIDs[studentCount] = strTok.nextToken(); studentNumberGrades[studentCount] = parseAnswers(testKey, strTok.nextToken()); studentCount++; } } public static void initFile() throws IOException { // Better to just include the file in the project; no changes to filename needed. inFile = new FileInputStream ("data.txt"); inReader = new InputStreamReader(inFile); reader = new BufferedReader(inReader); } public static char[] getKey() throws IOException { String line; StringTokenizer strTkn; line = reader.readLine(); strTkn = new StringTokenizer(line); String answerKey = strTkn.nextToken(); return answerKey.toCharArray(); } public static double parseAnswers(char[] key, String toCheck) { System.out.println("Parsing done.......!!!"); // Fill the method with your code // Takes test answers key and token from StringTokenizer // Return numeric grade for answers return 0.0; } }