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

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;

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

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;
      quiz[count] = new TFQuestion (QuestionSTMT, tfvalue);
      return true;
  public double play()
        Scanner keyboard = new Scanner (;
    for (int i = 0; i < quiz.length; 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

This article has been dead for over six months. Start a new discussion instead.