I have to select one of the following objectives:
//1. Make a parallel array of the number of correct answers. Send the method //answers and the answerKey. Return the filled parallel array that contains //the number correct.
correct = correctAnswer(answers, answerKey);
//2. Make a parallel array containing students' letter grades. Send correct
//and return the parallel array.
grade= getGrade(correct);
//3. Count how many of each grade
numOfEach=count(grade);
import java.io.*;
public class template
{
public static void main(String[] args) throws IOException
{
//creating objects and variables
int lineCount;
//count how many lines in the file
lineCount = countLines(counter);
String answerKey;
String[] studentID = new String[lineCount];//store student id
String[] answers = new String[lineCount];//store student answers
int[] correct = new int[lineCount];//store number they got correct
char[] grade = new char[lineCount];//store letter grade
char[] key = new char[10];//holds answer key
char[] numOfEach=new char[5];//hold number of each grade
//initialize file
initFile()
//Page 323 tells us that if I pass arrays the actual array will be modified so I can call a //method to read in the entire file
readFile(answers,studentID,key,lineCount);
//make parallel array of number of correct answers. Send the methods answers and // //answerKey return the filled parallel array containing the number correct.
correct= correctAnswer(answers, answerKey);
//Make a parallel array containing student’s letter grade. Send correct and return parallel //array.
grade= getGrade(correct);
//Count how many of each grade
numOfEach=count(grade);
//Output the desired results
outputResults(studentID, correct, grade);
}
}
I decided to select the last one "//3. Count how many of each grade
numOfEach=count(grade);"
I'm kind of stuck, so far I came up with this:
public static void count(char[] grade){
int numofa = 0, numofb = 0, numofc = 0, numofd = 0, numoff = 0;
for (int i = 0; i < grade.length; i++){
if (grade[i] == 'A'){
numofa++;
}else if (grade[i] == 'B'){
numofb++;
}else if (grade[i] == 'C'){
numofc++;
}else if (grade[i] == 'D'){
numofd++;
}else if (grade[i] == 'F'){
numoff++;
}
}
}
However, I don't know how to populate the numOfEach char array with the data I analyze (How many of each letter grade)