Hello, mhat01.
I've completed your java code, and it is available here:
http://xult.org/math01/License.java
It should be fairly self explanatory, as I've included useful comments
throughout. If anything's unclear though, please request clarification
before you rate this answer.
Good luck,
--seizer-ga |
Request for Answer Clarification by
math01-ga
on
10 Dec 2002 06:08 PST
Can you please explain the following lines:
import java.io.*;
catch (io exception e)
public static String getInput(String question) throws IOException {
// Display the question to the user
System.out.print(question);
// obtain their input
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// return that input
return in.readLine();
|
Request for Answer Clarification by
math01-ga
on
10 Dec 2002 06:15 PST
Also try!
|
Clarification of Answer by
seizer-ga
on
10 Dec 2002 06:19 PST
Certainly!
---
import java.io.*;
This line tells the compiler to include the standard Input and Output
classes, because we need to take input from the keyboard in the
program.
---
---
catch (IOException e)
This line means that we're able to catch an error, if there's a
problem with the Input and Output. So basically, if there's a keyboard
problem. It's good to do this, and Java insists. The try/catch
construct works like this:
try {
some things to try go here.
} catch (particular kinds of errors which might crop up while we're
trying the things above) {
things to do if there is an error
}
---
---
public static String getInput(String question) throws IOException {
// Display the question to the user
System.out.print(question);
// obtain their input
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
// return that input
return in.readLine();
}
This is a method which takes in a question to ask on the screen, and
returns a String object which contains the response which is typed in.
So line by line, it:
1) Prints the question on the screen
2) Reads in everything that is then typed on the keyboard, until the
user presses Enter
3) Returns that string to the place where it was called
---
Hope this helps!
--seizer-ga
|
Request for Answer Clarification by
math01-ga
on
10 Dec 2002 06:41 PST
Could I also use swing.* as well as JOptionPane.showInputDialog in this program?
|
Clarification of Answer by
seizer-ga
on
10 Dec 2002 07:18 PST
Hello, math01.
I'm not sure I understand your need for Swing. Swing is a group of
graphical classes designed for windowed programming. The core code is
certainly able to be slotted into a windowed program, of course.
If you're interested in graphical programming, your best approach
might be to post a fresh question, detailing additional requirements
or questions you may have. This will allow all the researchers a
chance to answer it.
Regards,
--seizer-ga
|
Request for Answer Clarification by
math01-ga
on
11 Dec 2002 01:11 PST
Hi seizer-ga,
Ran program and got error message:
Error: Method readline() not found in the class java.io.BufferedReader.
ProgLicense.java line 44 return in.readline();
|
Request for Answer Clarification by
math01-ga
on
11 Dec 2002 01:30 PST
Also getting error message:
Exception in thread "main" java.lang.NoClassDefFoundError: ProgLicense
|
Clarification of Answer by
seizer-ga
on
11 Dec 2002 03:57 PST
Hello math01.
The file *must* be called License.java, or the program will not work.
This is the same for all Java programs: the filename must be the same
as the class name.
As to the other error, you've got "readline". It should be "readLine".
Hope this helps!
--seizer-ga
|