Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    Hi guys am doing a java quiz game which will have:

    Question (superclass)
    Choicequestions (sub-class)
    Filling in question (sub-class)

    Quiz (test program)

    ive kinda managed to do the choice question class and works in test program.

    now i cant do the filling in question class any pointers any sample example you could give me to get started cheers.

    e.g.
    filling in question:

    Harry ______?

    A. is Potter
    Offline

    16
    ReputationRep:
    What do you have so far? What specifically are you having problems with?
    • Thread Starter
    Offline

    0
    ReputationRep:
    This is my question class:

    public class Question {

    protected String questionText;
    private String answer;

    public Question(String questionText) {
    this.questionText = questionText;
    answer = "";
    }

    public void setAnswer(String correctResponse) {
    answer = correctResponse;
    }

    public boolean checkAnswer(String response) {
    return response.equals(answer);

    }

    public void setquestion(String question) {
    this.questionText = question;
    }

    public String getquestion() {
    return questionText;
    }

    public static void addChoice(String string) {

    }

    public void display()
    {

    }


    }





    This is my choice question class:

    import java.util.ArrayList;

    public class Choicequestion extends Question {

    ArrayList<String> choices;

    public Choicequestion(String questionText) {
    super(questionText);
    choices = new ArrayList<String>();

    }

    public void addChoice(String choice, boolean correct) {

    choices.add(choice);
    if (correct) {
    String choiceString = "" + choices.size();
    setAnswer(choiceString);
    }
    }

    public void display()
    {
    super.display();
    for (int i = 0; i < choices.size(); i++)

    {
    int choiceNumber = i + 1;
    System.out.println(choiceNumber + ": " + choices.get(i));
    }

    }

    }


    the code above i did get some reference to a java book.

    now i want to built another class called filling in the missing words


    public class FillinQuestion extends Question {

    public String Fill;

    public FillinQuestion(String questionText) {
    super(questionText);
    }


    i know that i will extend this to the question class, now i just need help on how i will go about creating a missing word
    Offline

    16
    ReputationRep:
    Well, you're going to need two strings. One for the entered answer, one for the correct answer. Might be worth storing correct answers in lower case and then converting entered strings to lower case before comparing the two strings to ensure that answers aren't case sensitive.
 
 
 
    Discussions on TSR

  • Latest
  • Personalise
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.