Class 1, Part 2 | Intro to Java 30-IT-396 |
Getting Input
/*
* PromptMe.java
*
* Created on January 12, 2002, 7:01 PM
*/
// Import the swing package.
import javax.swing.*;
/**
* PromptMe
*
* A simple example of JOptionPane.showInputDialog(), if tests,
* and the equalsIgnoreCase() method of the String object.
*
*
* @author jonesbr@email.uc.edu
*/
public class PromptMe {
/** Creates a new instance of PromptMe */
public PromptMe() {
}
/**
* method queryUser()
*
* Prompts the user for certain information
via JOptionPane.showInputDialog().
* Displays this information to the user.
*
* @author jonesbr@email.uc.edu
*
*/
public void queryUser() {
// Prompt and display
age.
String age = JOptionPane.showInputDialog("How
old are you?");
System.out.println(age
+ " is a good age.");
// Prompt and display
'cheesy' question.
String star =
JOptionPane.showInputDialog("Who is the greatest college
basketball player of all time?");
// Note the use of equalsIgnoreCase
and ||. What would we get if we did
// not use these?
if(star.equalsIgnoreCase("oscar robertson")
|| star.equalsIgnoreCase("oscar") || star.equalsIgnoreCase("robertson"))
{
System.out.println("Yes, Oscar Robertson, from the University of
Cincinnati.");
} else {
System.out.println("No, silly, not " + star
+ ", it is UCs own Oscar Robertson!");
}
}
/**
* public static void main(String args[])
*
* Called from the command line.
Instantiates new PromptMe object, calls
* queryUser method.
*/
public static void main(String args[]) {
PromptMe promptMe =
new PromptMe();
promptMe.queryUser();
}
}
Created by: Brandan
Jones January 4, 2002