Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Help with java ASAP please

    this is what i have so far but im having trouble adding an accessor method for answer which i have called getAnswer


    public class Question {
    private String text;
    private String answer;
    private String getAnswer;


    /**
    * Constructs a question with empty question and answer.
    */
    public Question() {
    text = "";
    answer = "";
    }

    /**
    * Sets the question text.
    * @param questionText the text of this question
    */
    public void setText(String questionText) {
    text = questionText;
    }

    /**
    * Sets the answer for this question.
    * @param correctResponse the answer
    */
    public void setAnswer(String correctResponse) {
    answer = correctResponse;
    }

    public String getAnswer(){
    return answer;


    }

    /**
    * Checks a given response for correctness.
    * @param response the response to check
    * @return true if the response was correct, false otherwise
    */
    public boolean checkAnswer(String response) {
    return response.equals(answer);
    }

    /**
    * Displays this question.
    */

    public void display() {
    System.out.println(text);
    }


    }
    Last edited by seabass; 11-14-2010 at 05:10 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,799
    Thanks
    78
    Thanked 4,411 Times in 4,376 Posts
    This is the JavaSCRIPT forum.

    About the only thing that Java and JavaSCRIPT share are the first 4 letters of their names (and some superficial syntax similarities...but no more so than C and Java, for example).

    Try the JAVA forum.

    By the way, the answer to your question is easy.

    Code:
    private String getAnswer;
    ...
    public String getAnswer(){
    You can't have a method with the same name as a property.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    seabass (11-14-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •