|
Re: NEED Programming HELP ASAP!!
|
Posted: Sep 30, 2005 5:21 PM
|
|
Hi Phil,
Below is the code for the same ....
import java.net.URLEncoder; import java.util.Date; import java.util.StringTokenizer;
import atg.service.dynamo.GetMethodDroplet;
public class Question {
//assuming that you will set the missed asnwer ot -1 public final String MISSED_ANSWER= "-1"; TestInfo info = new TestInfo(); public static void main(String Args[]) {
String strCorrectAnswers[] ={"1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"," 1"} ; String strUserAnswers [] = {"1","1","worng","1","-1","1","1","1","1","1","1","1","1","1","1","1","1","1"," 1","1"} ; Question ques = new Question(); ques.checkPassed( strCorrectAnswers, strUserAnswers); ques.generateReport(); } /** * @return */ private void generateReport() { System.out.println(info.testResults()); }
public int checkPassed(String[] strQuestion, String strAnswers[]) { info = new TestInfo(); info.setTotalQuestion(strQuestion.length); for (int i=0;i<strQuestion.length; i++) { if(strQuestion.equals(strAnswers)) { info.incrementCorrectAnswer(); } // if the asnwer is wrong else if(!strAnswers.equals(MISSED_ANSWER)) { info.incrementWrongAnswer(); } } // end of for loop return -1; }
class TestInfo { /** * @return Returns the wronganswer. */ public int getWrongAnswer() { return wrongAnswer; } /** * @return */ public String testResults() { StringBuffer strBuffer = new StringBuffer(); strBuffer.append("\nTotal Answered Question " + (getCorrectAnswers()+ getWrongAnswer())); strBuffer.append("\nTotal Correct Answers " + (getCorrectAnswers())); strBuffer.append("\nTotal Worng Answers " + (getWrongAnswer())); strBuffer.append("\nTotal Missed Questions " + (getMissedQuestion())); strBuffer.append("\nTotal Question " + getTotalQuestion()); return (strBuffer.toString()); } /** * @return */ private int getMissedQuestion() { return (getTotalQuestion() - (getCorrectAnswers()+ getWrongAnswer())); } /** * */ public void incrementWrongAnswer() { wrongAnswer++; } /** * */ public void incrementCorrectAnswer() { correctAnswers++; } /** * @param wronganswer The wronganswer to set. */ public void setWrongAnswer(int wronganswer) { this.wrongAnswer = wronganswer; } private int correctAnswers = 0; private int wrongAnswer = 0; private int totalQuestion = 0; public TestInfo() { } /** * @return Returns the correctAnswers. */ public int getCorrectAnswers() { return correctAnswers; } /** * @param correctAnswers The correctAnswers to set. */ public void setCorrectAnswers(int correctAnswers) { this.correctAnswers = correctAnswers; } /** * @return Returns the totalQuestion. */ public int getTotalQuestion() { return totalQuestion; } /** * @param totalQuestion The totalQuestion to set. */ public void setTotalQuestion(int totalQuestion) { this.totalQuestion = totalQuestion; } }
}
-Zeon
|
|