java interface/call method help.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knane
    New Member
    • Nov 2009
    • 2

    #1

    java interface/call method help.

    Hi. Im not sure where or how to start off . Here is the question: Write a method askQuestion that takes a Question object and does all the work of asking the user the question, getting the user's response, and determining whether the response is correct. You could then simply call this method twice, once for q1 and once for q2.

    Code:
    import java.util.Scanner;
    
    public class MiniQuiz
    {
       //-----------------------------------------------------------------
       //  Presents a short quiz.
       //-----------------------------------------------------------------
       public static void main (String[] args)
       {
          Question q1, q2;
          String possible;
    
    Scanner scan = new Scanner(System.in);
    
          q1 = new Question ("What is the capital of Jamaica?",
                             "Kingston");
          q1.setComplexity (4);
    
          q2 = new Question ("Which is worse, ignorance or apathy?",
                             "I don't know and I don't care");
          q2.setComplexity (10);
    
          System.out.print (q1.getQuestion());
          System.out.println (" (Level: " + q1.getComplexity() + ")");
          possible = scan.nextLine();
          if (q1.answerCorrect(possible))
             System.out.println ("Correct");
          else
             System.out.println ("No, the answer is " + q1.getAnswer());
    
          System.out.println();
          System.out.print (q2.getQuestion());
          System.out.println (" (Level: " + q2.getComplexity() + ")");
          possible = scan.nextLine();
          if (q2.answerCorrect(possible))
             System.out.println ("Correct");
          else
             System.out.println ("No, the answer is " + q2.getAnswer());
       }
    }
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Are you getting errors with the code posted?

    Comment

    • knane
      New Member
      • Nov 2009
      • 2

      #3
      i'm trying to create a method like askQuestion which takes a Question object and does all the work of asking the user the question, getting the user's response, and determining whether the response is correct. And im trying to call the method once for q1 and q2

      Comment

      Working...