Need help with user input/output for GUI.
//This is my code so far. I'm suppose to have the user enter this:
user enters a int between <= 12 then would display this message Howdy youngster
user enters a int between >12 and <20 then would display another message displays You're getting old. etc..
I dont know how to set it up so the number i enter coordinates with the right message.
public class L4_SimpleCalc
{
public static void main (String arg[] )
{
JOptionPane.showMessageDialog(null, "The Old Man says:");
//Read in a value
String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");
//convert string to a number
double num1 = Double.parseDouble(enterNum);
JOptionPane.showMessageDialog(null, "Howdy youngster!");
JOptionPane.showMessageDialog(null, "Howdy, you're on your way!!");
JOptionPane.showMessageDialog(null, "Howdy, you're a mover and a shaker!");
JOptionPane.showMessageDialog(null, "Howdy, old timer!");
}
}
Re: Need help with user input/output for GUI.
Re: Need help with user input/output for GUI.
import javax.swing.*;
public class L4_SimpleCalc
{
public static void main (String[] args)
{
JOptionPane.showMessageDialog(null, "The Old Man says:");
//Read in a value
String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");
int age;
char text;
if (age <= 12){
text = "Howdy uoungster!";
} else if (age >12 and <20){
text = "Howdy, you're on your way!!";
} else if (age >=20 and <40){
text = "Howdy, you're a mover and a shaker!";
} else if (age >=40){
text = "Howdy, old timer!";
} else {
text = "too old";
}
}
Re: Need help with user input/output for GUI.
This still isnt right but im on the right track I need it to work like that. how do i enter a value and have it come out in GUI with the right message?
Quote:
Originally Posted by
Tctwins
import javax.swing.*;
public class L4_SimpleCalc
{
public static void main (String[] args)
{
JOptionPane.showMessageDialog(null, "The Old Man says:");
//Read in a value
String enterNum = JOptionPane.showInputDialog(null, "What is your age?:");
int age;
char text;
if (age <= 12){
text = "Howdy uoungster!";
} else if (age >12 and <20){
text = "Howdy, you're on your way!!";
} else if (age >=20 and <40){
text = "Howdy, you're a mover and a shaker!";
} else if (age >=40){
text = "Howdy, old timer!";
} else {
text = "too old";
}
}
Re: Need help with user input/output for GUI.
When do you set age? What do you do with enterNum?
Re: Need help with user input/output for GUI.
Quote:
Originally Posted by
KevinWorkman
When do you set age? What do you do with enterNum?
im lost..bad. I just wanna be able to enter a number and have that number go to the correct statement. if you could guide me out a little bit it would be a better learning process.
Re: Need help with user input/output for GUI.
If you figure out the answers to the question I asked you, you'll figure out why you're getting compiler errors.