Quote (irimi @ Jul 30 2012 02:41pm)
You might want to start by writing a unit test for the method.
I did.
http://pastebin.com/4vQ61Pq0Code
public void testFillInTheBlanks() {
StringBuffer answer = new StringBuffer();
SystemManager manager = new SystemManager();
manager.addExam(10, "Midterm");
double points;
String questionText = "Name two types of initialization blocks.";
points = 4;
manager.addFillInTheBlanksQuestion(10, 1, questionText, points, new String[]{"static","non-static"});
questionText = "Name the first three types of primitive types discussed in class.";
points = 6;
manager.addFillInTheBlanksQuestion(10, 2, questionText, points, new String[]{"int","double","boolean"});
String studentName = "Peterson,Rose";
manager.addStudent(studentName);
manager.answerFillInTheBlanksQuestion(studentName, 10, 1, new String[]{"static", "non-static"});
manager.answerFillInTheBlanksQuestion(studentName, 10, 2, new String[]{"int", "double", "boolean"});
answer.append("Report for " + studentName + "\n" + manager.getGradingReport(studentName, 10));
studentName = "Sanders,Laura";
manager.addStudent(studentName);
manager.answerFillInTheBlanksQuestion(studentName, 10, 1, new String[]{"static"});
manager.answerFillInTheBlanksQuestion(studentName, 10, 2, new String[]{"int", "boolean"});
answer.append("\nReport for " + studentName + "\n" + manager.getGradingReport(studentName, 10));
System.out.println(answer.toString());
assertTrue(TestingSupport.correctResults("pubTestFillInTheBlanks.txt", answer.toString()));
}
The report should look like:
Report for Peterson,Rose
Question #1 4.0 points out of 4.0
Question #2 6.0 points out of 6.0
Final Score: 10.0 out of 10.0
Report for Sanders,Laura
Question #1 2.0 points out of 4.0
Question #2 4.0 points out of 6.0
Final Score: 6.0 out of 10.0
But instead it looks like:
Report for Peterson,Rose
Question # 1 0.0 points out of 4.0
Question # 2 0.0 points out of 6.0
Final Score: 0.0 out of 0.0
Report for Sanders,Laura
Question # 1 0.0 points out of 4.0
Question # 2 0.0 points out of 6.0
Final Score: 0.0 out of 0.0
Because it's not adding the points correctly because I'm guessing the method I use to see if the answer is correct isn't working correctly.
It's the else statement part when I'm directly testing fill-in-the-blank answers in getGradingReport in SystemManager
Code
}else{
examFillInBlankAnswers = e.getKey(questionNumber).getAnswer().split(",");
for(String subString : examFillInBlankAnswers){
examAnswers.add(subString);
}
for(String answer : examAnswers){
if(studentAnswers.contains(answer)){
totalStudentPoints += e.getKey(questionNumber).getPoints()/examAnswers.size();
questionPoints += e.getKey(questionNumber).getPoints()/examAnswers.size();
}else{
totalStudentPoints += 0;
questionPoints += 0;
}
}
s += "Question # " + questionNumber + " " + questionPoints
+ " points out of " + e.getKey(questionNumber).getPoints() + "\n";
questionNumber++;
}
}
}
}
This post was edited by lopelurag on Jul 30 2012 12:56pm