The Artima Developer Community
Sponsored Link

Java Answers Forum
NEED Programming HELP ASAP!!

1 reply on 1 page. Most recent reply: Sep 30, 2005 5:21 PM by Subodh Rawat

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Phillip

Posts: 1
Nickname: husker7
Registered: Sep, 2005

NEED Programming HELP ASAP!! Posted: Sep 30, 2005 12:51 PM
Reply to this message Reply
Advertisement
Hi, I'm trying to create a class that holds 2 String arrays, one with the 20 right answers to a test and one with 20 answers that has someone put into the program to check with the right answers, if you pass you got 15 out of 20 right. I'm trying to figure out how I can make these 4 methods: passed-returns true if the student passed the exam and false if they faild, totalCorrect-returns the total number of correctly answered question, totalInCorrect-return the total incorrect, and questionsMissed-an int array containing the question numbers of teh questions the student misses! I have no idea on how to make these methods! Please someone help!
Thanks!
Phil


Subodh Rawat

Posts: 9
Nickname: zeon
Registered: May, 2005

Re: NEED Programming HELP ASAP!! Posted: Sep 30, 2005 5:21 PM
Reply to this message Reply
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

Flat View: This topic has 1 reply on 1 page
Topic: Applet filter won't work Previous Topic   Next Topic Topic: how to position scrollbar in scrollpane

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use