Hi there. This question is not for the faint of heart and will be time consuming..
I am learning Java, and I was wondering if anyone could walk me through my program to tell me what I did wrong and how I can fix it so that I can learn.
My whole program (in case this is needed): http://pastie.org/private/xpbgpypetvfmivcs88gbcq
Assignment:
Not allowed to use global variables! You have been asked to write a program to grade the results of a true-false quiz and display the results in tabular form. The quiz consists of 10 questions. The data file for this problem consists of 1 set of correct responses (answerkey) on line one and succeeding lines containing a four digit student identification number followed by that student's 10 responses. (The number of students taking the quiz in currently unknown.)
The data file is in the form :
TFFTFTTFTT
0461 TTFTTFTFTT
3218 TFFTTTTTFT
.....................
....................
Your program should read the key and store it in a one dimensional array. It should then read and process each succeeding line, storing the student identification numbers in a one dimensional array and the grades in two separate one dimensional arrays- one for numeric grades and the for letter grades.
Numeric grades are converted to letter according to the following system : A(10), B(9), C(8-7), D (6-5), F(4-0).
Program output should include the following :
Each Student's four digit identification number, their numeric grade and their letter grade.
A printed count of how many students took the quiz.
The numeric quiz average for the entire class.
A frequency count of the number of A's, B's, C's,D's and F's for the entire class.
EDIT:
Oh, hey. Sorry, I am still getting the hang of how to do all of this :( Alright, here goes.
The program is not compiling, and I am pretty sure it's down to my logic. (As well as some syntactical stuff).
What I'm having trouble with: 1) How to pass all of the parameters to each of the different methods, as seen here. What I would LIKE to do is have all of my values that I return such as answerKey, studentAnswers, numericGrade, average etc be up here so that I can use them and print them. But I do not know how to do that.
int[] numericGrade = computeNumericGrade(answerKey, studentAnswers);
int[] letterGrade = computeLetterGrade(numericGrade);
double average = average(numericGrade);
int gradeTally = gradeTally(letterGrade);
int studentCount = studentCount(numericGrade);
2) I cannot figure out how to individually check through each of the T or F values and check if it corresponds with the T or F in the answer key, as seen below.
What I am trying to do is to check through each letter at a specific element, and if the value is "correct" or == to answerKey, then add to the total in numericGrade for that element.
public static int[] computeNumericGrade(int[] answerKey, int[] studentAnswers) {
int[] numericGrade = new int[50];
int total = 0;
for(int i = 0; i < 50;i++) {
for(int a = 0;a == 10;a++) {
total = studentAnswers[i].charAt(a);
if(total == answerKey[i]) numericGrade[i]++;
}
}
return numericGrade;
}
3) I do not know how to return all of these different values, as I need them all above! I want this set of code to check the letter grade of each element and if this element is found, ++ the variable that corresponds to it, so I know how many of this letter grade was called.
public static int gradeTally(String[] letterGrade) {
int a, b, c, d, f = 0;
for(int i = 0;i < letterGrade.length;i++) {
if(letterGrade[i] == 'A') a++;
else if (letterGrade[i] == 'B') b++;
else if (letterGrade[i] == 'C') c++;
else if (letterGrade[i] == 'D') d++;
else if (letterGrade[i] == 'F') f++;
}
return a + b + c + d + f;
}
4) I can't figure this out... I think I am close. Here, I am trying to read the file, tokenize it, and then for each token, add it to the array 1 by 1. However, I don't think that's it's doing that properly, but I can't check since I can't get it to compile...
public static String[] getData() throws IOException {
int[] studentID = new int[50];
String[] studentAnswers = new String[50];
int total = 0;
String line = reader.readLine();
strTkn = new StringTokenizer(line);
String answerKey = strTkn.nextToken();
while(line != null) {
studentID[total] = Integer.parseInt(strTkn.nextToken());
studentAnswers[total] = strTkn.nextToken();
total++;
}
return studentAnswers;
}
I am now done editing my post. I hope this is sufficient :)