Back to the Program-A-Day homepage
Problem
Lets create a program which takes some text input from a user and then makes a Mad Lib out of it.
We're going to look at making this application using JOptionPane with both input and output.
|
|
...by students
An image or By Students section
|
Solution
The solution...
|
Code
Solution Code
import javax.swing.JOptionPane;
public class MadLib
{
public static void main(String []args)
{
String pluralNoun;
String country;
String verb;
String noun;
pluralNoun = JOptionPane.showInputDialog("Please enter a plural noun:");
country = JOptionPane.showInputDialog("Please enter a name of a country:");
verb = JOptionPane.showInputDialog("Please enter a verb:");
noun = JOptionPane.showInputDialog("Please enter a noun:");
// "The ___________ in _______ like to ____ the ____."
// plural noun country verb noun
JOptionPane.showMessageDialog("The " + pluralNoun + " in " + country + " like to " + verb + " the " + noun + ".");
}
}
|
Back to the Program-A-Day homepage