473,385 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

java interface/call method help.

2
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.  
Nov 9 '09 #1
2 1997
Dököll
2,364 Expert 2GB
Are you getting errors with the code posted?
Nov 9 '09 #2
knane
2
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
Nov 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: ramasubramanian.rahul | last post by:
hi i am trying to call some java APIs from c . i use the standatd JNI calls to load the JVM from a c program and call all java functions by using a pointer to the jvm which was returned by the JNI...
0
by: r035198x | last post by:
Overriding therefore allows you to use the same method name to refer to differently implemented methods. Here is an example using the famous shapes example. class Shape { public Shape()...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs....
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.