Connecting Tech Pros Worldwide Help | Site Map

java interface/call method help.

Newbie
 
Join Date: Nov 2009
Posts: 2
#1: 1 Week Ago
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.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class MiniQuiz
  4. {
  5.    //-----------------------------------------------------------------
  6.    //  Presents a short quiz.
  7.    //-----------------------------------------------------------------
  8.    public static void main (String[] args)
  9.    {
  10.       Question q1, q2;
  11.       String possible;
  12.  
  13. Scanner scan = new Scanner(System.in);
  14.  
  15.       q1 = new Question ("What is the capital of Jamaica?",
  16.                          "Kingston");
  17.       q1.setComplexity (4);
  18.  
  19.       q2 = new Question ("Which is worse, ignorance or apathy?",
  20.                          "I don't know and I don't care");
  21.       q2.setComplexity (10);
  22.  
  23.       System.out.print (q1.getQuestion());
  24.       System.out.println (" (Level: " + q1.getComplexity() + ")");
  25.       possible = scan.nextLine();
  26.       if (q1.answerCorrect(possible))
  27.          System.out.println ("Correct");
  28.       else
  29.          System.out.println ("No, the answer is " + q1.getAnswer());
  30.  
  31.       System.out.println();
  32.       System.out.print (q2.getQuestion());
  33.       System.out.println (" (Level: " + q2.getComplexity() + ")");
  34.       possible = scan.nextLine();
  35.       if (q2.answerCorrect(possible))
  36.          System.out.println ("Correct");
  37.       else
  38.          System.out.println ("No, the answer is " + q2.getAnswer());
  39.    }
  40. }
  41.  
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,260
#2: 1 Week Ago

re: java interface/call method help.


Are you getting errors with the code posted?
Newbie
 
Join Date: Nov 2009
Posts: 2
#3: 1 Week Ago

re: java interface/call method help.


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
Reply