d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Problem
Add Reply New Topic New Poll
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 30 2012 12:38pm
So my problem is the getGradingReport in SystemManager specifically for fill-in-the-blank questions.

I can't get it to grade the answers for fill in the blank questions correctly and I can't figure out a way without altering all of my code.

I'm trying to compare the exam answer to the array of student answers and see if the array contains the character sequence, problem is I can't seem to get it to work.

Anyone have any idea what I can do without altering all my code? OR an easy way that may require me to alter my code?

Literally the only thing that doesn't work is the getGradingReport, I'll tip heavily if anyone can give me some significant help! ^_^


- - - - Classes - - - - -

System Manager - http://pastebin.com/0cDwzd4g

Student - http://pastebin.com/JsebgQPM

Answer (defines a student answer) - http://pastebin.com/SFPpHPzM

Exam - http://pastebin.com/eihQY9VA

Question (defines an exam question + correct answer) - http://pastebin.com/e0vQwgK7

Please post any questions you have
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Jul 30 2012 12:41pm
You might want to start by writing a unit test for the method.
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 30 2012 12:54pm
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/4vQ61Pq0

Code
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
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 30 2012 01:07pm
This is a new else statement I formed, the only problem is if they don't enter the entire correct answer, it will not give them partial credit for any answer they did get correct for the question number as FITB questions can have multiple blanks..

Pretty much trying to find a way to fix the 2nd else in this statement so that if the student answer contains any part of the correct answer they get partial credit.

Code
}else{
     if(studentAnswers.get(questionNumber - 1).compareTo
       (e.getKey(questionNumber).getAnswer()) == 0){

      totalStudentPoints += e.getKey(questionNumber).getPoints();
      s += "Question # " + questionNumber + " " + e.getKey(questionNumber).getPoints()
        + " points out of " + e.getKey(questionNumber).getPoints() + "\n";
     }else{
      s += "Question # " + questionNumber + " " + 0.0
        + " points out of " + e.getKey(questionNumber).getPoints() + "\n";
     }
     totalExamPoints += e.getKey(questionNumber).getPoints();
     questionNumber++;
    }


This post was edited by lopelurag on Jul 30 2012 01:07pm
Member
Posts: 4,605
Joined: Sep 15 2011
Gold: 9,464.00
Jul 30 2012 02:13pm
Your unit test is a bit too complicated to actually help you with debugging anything. It calls several methods in your class (which are presumably untested as well), and it doesn't even aim to test the method you think you're having trouble with (it's called testFillInTheBlanks, not testGetGradingReport). This is partly why the unit test is ineffective in helping you isolate the problem in your code.

I don't really care to go into the specifics of your code, but broadly speaking, two things could be going wrong here: either you're putting the information into the wrong place (input), or you're retrieving them from the wrong place (output). You should write some tests that first verify that your input is correct, and then write some tests that verify that your output is correct. Trying to do both is a pointless exercise until you have them individually covered.
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 30 2012 03:00pm
Quote (irimi @ Jul 30 2012 04:13pm)
Your unit test is a bit too complicated to actually help you with debugging anything.  It calls several methods in your class (which are presumably untested as well), and it doesn't even aim to test the method you think you're having trouble with (it's called testFillInTheBlanks, not testGetGradingReport).  This is partly why the unit test is ineffective in helping you isolate the problem in your code.

I don't really care to go into the specifics of your code, but broadly speaking, two things could be going wrong here:  either you're putting the information into the wrong place (input), or you're retrieving them from the wrong place (output).  You should write some tests that first verify that your input is correct, and then write some tests that verify that your output is correct.  Trying to do both is a pointless exercise until you have them individually covered.


Actaully the junit test works perfectly, as the only place the code is having problems is in the getGradingReport method.

getGradingReport just sees if the answer is correct and prints out the associated points earned with the question

Everything is correct except for that specific else statement in the getGradingReport method.




Since fill in the blank answers can get partial credit if they give some of the correct answers, I can't compare the entire string answer because that ignores a chance for partial credit.

I'm working on breaking up the two strings into to separate arrays and then using contains to see if the student answers contains correct answers.

Working on the 2nd else statement below to compare to arrays that are not the same when made into a string, aka the student left a fill in the blank empty or gave an incorrect answer.

Code
}else{
     if(studentAnswers.get(questionNumber - 1).compareTo
       (e.getKey(questionNumber).getAnswer()) == 0){

      totalStudentPoints += e.getKey(questionNumber).getPoints();
      s += "Question # " + questionNumber + " " + e.getKey(questionNumber).getPoints()
        + " points out of " + e.getKey(questionNumber).getPoints() + "\n";
     }else{
      String ans = e.getKey(questionNumber).getAnswer();
      ans = e.getKey(questionNumber).getAnswer().substring(1, ans.indexOf("]"));
      StringBuffer sbuffer = new StringBuffer();
      sbuffer.append(studentAnswers.get(questionNumber - 1));
      System.out.println(sbuffer);
      ans.contentEquals(sbuffer);
     
      s += "Question # " + questionNumber + " " + 0.0
        + " points out of " + e.getKey(questionNumber).getPoints() + "\n";
     }
     totalExamPoints += e.getKey(questionNumber).getPoints();
     questionNumber++;
    }


At the moment the report prints out like, since the student Sanders answered some questions incorrectly thus it moves to my broken else statement.

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 0.0 points out of 4.0
Question #2 0.0 points out of 6.0
Final Score: 0.0 out of 10.0

This post was edited by lopelurag on Jul 30 2012 03:03pm
Member
Posts: 24,101
Joined: Nov 8 2007
Gold: 5,561.70
Jul 30 2012 03:40pm
Got it fixed nvm!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll