In Java Only: My program is not working correctly, The history teacher at your school needs help grading a true/false test.The student's IDs and test answers are stored ina file, The first entry in the file contains the answers to the test in the following form: TFFTFFTTTTFFTFTFTFTT Every other entry in the file is the student;s ID, followed by a blank, followed by the student;s response. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT indicstes that the student;s ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is false, and so on. This student did not answer question 9. he exam has 20 questions, and the class has more than 150 students.  Each correct answer is awarded 2 points, each wrong answer gets -1 point, and no answer gets 0 points. Write a program that processes the test data. The output should be the student's ID, followed by the student's answers, followed by the test score, and then followed by the test grade. Here is my code, I keep getting a NullPointerException when I am calling the method cacluatePoints and when checking the students answers is = to ' ' in the calculatePoints method. I tried everything. Thank you     My Code: public class EditededHistoryTest { static final int MAX_QUESTIONS = 20; static final int MAX_NUM_OF_STUDENTS = 12; /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { // String[] answerKey = new String[MAX_QUESTIONS]; String[] studentID = new String[8]; //String studentID; // String[] studentAnswers = new String[MAX_QUESTIONS]; char[] answerKey = new char[MAX_QUESTIONS]; char[] studentAnswers = new char [MAX_QUESTIONS]; int score;//send this score into the method CalculatePercentgegrade int[]percentageScore = new int[MAX_QUESTIONS]; char[]testGrade = new char[MAX_NUM_OF_STUDENTS]; //int len; int i;//initialize the index to start at counting at zero int[]studentScores = new int[MAX_NUM_OF_STUDENTS]; String inputLine; int blankSpace; Scanner inFile = new Scanner(new FileReader("e:\\historytestmodule.txt")); PrintWriter outFile = new PrintWriter("historytestmoduleOut.dat"); outFile.println("GRADING DATA: "); System.out.println("GRADING DATA: "); //Read the answer key inputLine = inFile.nextLine(); //inputLine = inFile.nextLine(); // answerKey[i] = inFile.nextLine(); for(i = 0; i < answerKey.length; i++){ // answerKey[i]= inputLine.substring(0,inputLine.length()); answerKey[i]= inputLine.charAt(i); // if(answerKey[i] = inputLine.charAt(i) == null) // {System.out.println("kkkanswerkey array is null"); // } //else{ // System.out.println("KKKKanswerkey array is not null"); System.out.print(answerKey[i]); }System.out.println("the length of the input line " + inputLine.length()); System.out.println("Whats in the iinput line after you gettheanswer key" + inputLine); // System.out.println(" Answer Key:" + " " + answerKey[i]); // outFile.printf("Answers Key: %20s%n",answerKey[i]); int index = 0; //get the student's IDs and the student's answers int numOfStudents = 0; while(inFile.hasNext() && numOfStudents < MAX_NUM_OF_STUDENTS) { //Get the first students' ID and test answers inputLine = inFile.next(); studentID[index] = inputLine.substring(0) //Go to the next line and get the student's test answers and //get the index of blankspace between the text inputLine = inFile.nextLine(); blankSpace = inputLine.indexOf(' ');//at this point the kength o for(i = 0; i < studentAnswers.length; i++){ studentAnswers[i] = inputLine.substring(blankSpace + 1, inputLine.length()); } System.out.println(); numOfStudents++; }  System.out.println(calculatePoints(answerKey, studentAnswers // for(i = 0; i < studentAnswers.length; i++) //{ //} //calculatePercentageScore(studentScores, maxPoints);//might have to send this from the method // CalculateGrades(studentScores, testGrade); //Do output here //System.out.println("the kids grades" + testGrade ); //System.out.println(studentID + studentAnswers + calculatePoints(answerKey, studentAnswers )); //System.out.printf(String.format("%s %s %2d %c %n",studentID, studentAnswers,calculatePoints(answerKey, studentAnswers))); // outFile.printf(String.format("%9s %21s %n", // studentID[i],studentAnswers[i]));///the student grades have to print here // outFile.printf(String.format("%9s %21s %2d %2c%n", // studentID[i],studentAnswer, score, testGrade(score))); //inFile.close(); outFile.close(); }//end of the Main method public static int calculatePoints(char[]keyAns, char[]stuAnswers) { //int len = keyAns.length; int testScores = 0; int i; int correct = 0,incorrect = 0, omit = 0 // sum = 0; for(i = 0; i < stuAnswers.length; i++) {  if(stuAnswers[i] == ' ')//this has a null pointer exception       { omit = 0;       } else if(stuAnswers[i]== keyAns[i]) { correct = correct + 2; } else { incorrect = incorrect - 1; } testScores = correct - incorrect + omit; return testScores; } }//end of HistoryTest Class

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

In Java Only: My program is not working correctly, The history teacher at your school needs help grading a true/false test.The student's IDs and test answers are stored ina file, The first entry in the file contains the answers to the test in the following form: TFFTFFTTTTFFTFTFTFTT

Every other entry in the file is the student;s ID, followed by a blank, followed by the student;s response. For example, the entry: ABC54301 TFTFTFTT TFTFTFFTTFT

indicstes that the student;s ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is false, and so on. This student did not answer question 9. he exam has 20 questions, and the class has more than 150 students. 

Each correct answer is awarded 2 points, each wrong answer gets -1 point, and no answer gets 0 points. Write a program that processes the test data. The output should be the student's ID, followed by the student's answers, followed by the test score, and then followed by the test grade.

Here is my code, I keep getting a NullPointerException when I am calling the method cacluatePoints and when checking the students answers is = to ' ' in the calculatePoints method. I tried everything. Thank you

 

 

My Code:

public class EditededHistoryTest {

static final int MAX_QUESTIONS = 20;
static final int MAX_NUM_OF_STUDENTS = 12;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException
{
// String[] answerKey = new String[MAX_QUESTIONS];
String[] studentID = new String[8];
//String studentID;
// String[] studentAnswers = new String[MAX_QUESTIONS];
char[] answerKey = new char[MAX_QUESTIONS];
char[] studentAnswers = new char [MAX_QUESTIONS];
int score;//send this score into the method CalculatePercentgegrade
int[]percentageScore = new int[MAX_QUESTIONS];
char[]testGrade = new char[MAX_NUM_OF_STUDENTS];
//int len;
int i;//initialize the index to start at counting at zero
int[]studentScores = new int[MAX_NUM_OF_STUDENTS];
String inputLine;
int blankSpace;

Scanner inFile = new Scanner(new FileReader("e:\\historytestmodule.txt"));
PrintWriter outFile = new PrintWriter("historytestmoduleOut.dat");

outFile.println("GRADING DATA: ");
System.out.println("GRADING DATA: ");

//Read the answer key
inputLine = inFile.nextLine();
//inputLine = inFile.nextLine();
// answerKey[i] = inFile.nextLine();
for(i = 0; i < answerKey.length; i++){
// answerKey[i]= inputLine.substring(0,inputLine.length());
answerKey[i]= inputLine.charAt(i);

// if(answerKey[i] = inputLine.charAt(i) == null)
// {System.out.println("kkkanswerkey array is null");

// }
//else{
// System.out.println("KKKKanswerkey array is not null");

System.out.print(answerKey[i]);
}System.out.println("the length of the input line " + inputLine.length());

System.out.println("Whats in the iinput line after you gettheanswer key" + inputLine);
// System.out.println(" Answer Key:" + " " + answerKey[i]);

// outFile.printf("Answers Key: %20s%n",answerKey[i]);



int index = 0;
//get the student's IDs and the student's answers
int numOfStudents = 0;
while(inFile.hasNext() && numOfStudents < MAX_NUM_OF_STUDENTS)

{
//Get the first students' ID and test answers
inputLine = inFile.next();

studentID[index] = inputLine.substring(0)
//Go to the next line and get the student's test answers and
//get the index of blankspace between the text
inputLine = inFile.nextLine();
blankSpace = inputLine.indexOf(' ');//at this point the kength o
for(i = 0; i < studentAnswers.length; i++){

studentAnswers[i] = inputLine.substring(blankSpace + 1, inputLine.length());

} System.out.println();
numOfStudents++;

System.out.println(calculatePoints(answerKey, studentAnswers



// for(i = 0; i < studentAnswers.length; i++)
//{

//}



//calculatePercentageScore(studentScores, maxPoints);//might have to send this from the method
// CalculateGrades(studentScores, testGrade);
//Do output here
//System.out.println("the kids grades" + testGrade );
//System.out.println(studentID + studentAnswers + calculatePoints(answerKey, studentAnswers ));
//System.out.printf(String.format("%s %s %2d %c %n",studentID, studentAnswers,calculatePoints(answerKey, studentAnswers)));


// outFile.printf(String.format("%9s %21s %n",
// studentID[i],studentAnswers[i]));///the student grades have to print here



// outFile.printf(String.format("%9s %21s %2d %2c%n",
// studentID[i],studentAnswer, score, testGrade(score)));
//inFile.close();
outFile.close();
}//end of the Main method

public static int calculatePoints(char[]keyAns, char[]stuAnswers)
{
//int len = keyAns.length;
int testScores = 0;
int i;



int correct = 0,incorrect = 0, omit = 0

// sum = 0;





for(i = 0; i < stuAnswers.length; i++)

{
 if(stuAnswers[i] == ' ')//this has a null pointer exception
      { omit = 0;

      }
else if(stuAnswers[i]== keyAns[i])
{
correct = correct + 2;

}
else {

incorrect = incorrect - 1;

}
testScores = correct - incorrect + omit;

return testScores;

}







}//end of HistoryTest Class

 

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY