Skip to main content

Need a solution....pls

2 replies [Last post]
andrewooi
Offline
Joined: 2010-03-13

Hi all. i am new in this java programming.
i wonder that someone can give me a clue to solve this source code that i made.

source code:
import javax.swing.*;
public class Dialog
{
public static void main(String[] args)
{
int text = 0; // Assign text as user keyin data

String num1 = JOptionPane.showInputDialog("Enter temperature:");

text = Integer.parseInt(num1); // Conversion Strings to Integers

if(text < 10) {JOptionPane.showMessageDialog(null,"Too Cold","Output",
JOptionPane.INFORMATION_MESSAGE);
}

if(text >= 10 && text <= 20) {JOptionPane.showMessageDialog(null,"Average","Output",
JOptionPane.INFORMATION_MESSAGE);
}

if(text >= 21 && text <= 30) {JOptionPane.showMessageDialog(null,"Hot","Output",
JOptionPane.INFORMATION_MESSAGE);
}

if(text > 30) {JOptionPane.showMessageDialog(null,"Too Hot","Output",
JOptionPane.INFORMATION_MESSAGE);
}
option_user();

}

public static void option_user()
{

String num2 = JOptionPane.showInputDialog("Would you like to continue (y/n):");

if (num2.equals("y")) ?????
if (num2.equals("n"))

System.exit(0); //Terminates the program after user click the ok button in the dialog box.

}

}

My question:
if (num2.equals("y")) .... i want if the user type "y" then go to main for loop again.
what are the code that i should write in?
Java expert...pls give me a clue....tq

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
arsenal4ever_11
Offline
Joined: 2010-04-28

hi andrewooi
for your Q:where is the loop ??

and in your program there is a mistake :
your mistake is
if(text >= 10 && text = 21 && text 30)
the correct one is
if(text >= 10 && text == 21 && text== 30)

and thak you =)

gvitor
Offline
Joined: 2010-04-23

Hi, hope this snippet code answer your question.

int i = JOptionPane.showConfirmDialog(null, "Is that what you want?", "Question title", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

if(i==0){
System.out.println("Yes option");
}
else{
System.out.println("No option");
}

Regards,
Giuliano.