| | |
java code help 2;;
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 5
Reputation:
Solved Threads: 0
instruction for quiz
Next, write a class Quiz that represents a quiz consisting of true/false questions. This class should have exactly two instance variables: a one-dimensional array of TFQuestions that stores all the true/false questions of the quiz, and an int variable that records the number of true/false questions in the array (because the array may contain unused cells). This class should provide the following public methods:
* public Quiz(int capacity): this constructor initializes the two instance variables by creating an array of TFQuestions of size capacity and setting the number of true/false questions to zero.
* public boolean add(String questionStmt, boolean correctAnswer): this method creates a TFQuestion object representing a true/false question with statement questionStmt and correct answer correctAnswer, inserts this question into the array, and returns true. However, if the array is already full, then no TFQuestion object will be created and added to the array, and this method should return false instead.
* public double play(): this method allows the user to take the quiz once. It should display a true/false question on the screen, prompt the user to enter the answer for that question in the form "t" (for true) or "f" (for false), then display the next question, and so on. The questions should be displayed in the same order that they were added to the array. Finally, this method should return the score as the percentage of questions that have been answered correctly. Note that if the array contains no true/false questions, then this method should display the sentence "This quiz has no questions!" and simply return 100%.
please help me
so far i got code for tfquestion because someone helped me in this site
And I am trying to make another code which is quiz, this one connected from tfquestion and also i have to make quizdriver so i have to make 3 classes tfquestion, quiz, quizdriver. But i really want to ask is about quiz.I couldn't ask about quizdriver yet, because I didn't do it yet...
here is my code for quiz
the quiz code it self uses array, too...
I really not sure about code in boolean add and double play
please help me
and thx to the repliers for tfquestion code
Next, write a class Quiz that represents a quiz consisting of true/false questions. This class should have exactly two instance variables: a one-dimensional array of TFQuestions that stores all the true/false questions of the quiz, and an int variable that records the number of true/false questions in the array (because the array may contain unused cells). This class should provide the following public methods:
* public Quiz(int capacity): this constructor initializes the two instance variables by creating an array of TFQuestions of size capacity and setting the number of true/false questions to zero.
* public boolean add(String questionStmt, boolean correctAnswer): this method creates a TFQuestion object representing a true/false question with statement questionStmt and correct answer correctAnswer, inserts this question into the array, and returns true. However, if the array is already full, then no TFQuestion object will be created and added to the array, and this method should return false instead.
* public double play(): this method allows the user to take the quiz once. It should display a true/false question on the screen, prompt the user to enter the answer for that question in the form "t" (for true) or "f" (for false), then display the next question, and so on. The questions should be displayed in the same order that they were added to the array. Finally, this method should return the score as the percentage of questions that have been answered correctly. Note that if the array contains no true/false questions, then this method should display the sentence "This quiz has no questions!" and simply return 100%.
please help me
so far i got code for tfquestion because someone helped me in this site
Java Syntax (Toggle Plain Text)
public class TFQuestion { String tfQuestion; boolean cAnswer; public TFQuestion(String tfQtion, boolean tfvalue) { tfQuestion = tfQtion; cAnswer = tfvalue; } public String toString() { return tfQuestion; } public boolean checkAnswer(boolean userAnswer) { return userAnswer == cAnswer; } }
here is my code for quiz
Java Syntax (Toggle Plain Text)
public class Quiz { private TFQuestion[] Quiz; private int count; public Quiz(int capacity) { capacity = 20; Quiz = new TFQuestion[capacity]; count = 0; } public boolean add (String QuestionSTMT, boolean Answer) { if (count >= quiz.length) return false; else quiz[count] = new TFQuestion (QuestionSTMT, tfvalue); count++; return true; } public double play() { Scanner keyboard = new Scanner (System.in); for (int i = 0; i < quiz.length; i++) { System.out.println(quiz[i]); System.out.println("Enter the answer for this question with 't' for true and 'f'" + " for false."); char answer = keyboard.nextChar(); double numQuestions = ((double) i); if (answer == correctAnswer) double numCorrect++; } double percentage = (numCorrect/numQuestions) * 100.0; return percentage; } }
the quiz code it self uses array, too...
I really not sure about code in boolean add and double play
please help me
and thx to the repliers for tfquestion code
Last edited by ~s.o.s~; May 3rd, 2008 at 12:52 pm. Reason: Added code tags, learn to use them; last warning.
![]() |
Similar Threads
- Java/J2EE Senior Software Engineer (Software Development Job Offers)
- Auto generate Java Code from WSDL using Axis (Java)
- Executing Shell script from Java code. (Java)
- download jar files using java code (Java)
- I want to know about the java code. Help please!!!! (Java)
- Move out java code from jsp (Java)
- Help with Java code (Java)
- Can N E 1 Help!!!! -- Need sample Java code (Java)
- java code newbie (Java)
Other Threads in the Java Forum
- Previous Thread: Who can teach me combine these 2 class?
- Next Thread: java
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows





