Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to make a very simple program with Netbean using Java. I got to the

ID: 3767276 • Letter: I

Question

I am trying to make a very simple program with Netbean using Java.

I got to the point where dialog box pops up and asks please enter some text.

I want the output to say please enter an integer if I type in something that is not integer inside the box.

And if I type in the integer the output would be that integer that I typed in.

I want the dialog box to stay for three tries. After that the box will disappear whether I typed in integer or not.

I am not sure how to deal with if (reply != int) part and how I should make the box stay up for three tries.

Could anybody help me with this?

{
JOptionPane dialog;
dialog = new JOptionPane ();
String textMessage = "Please enter some text:";
String reply = "";
  
while(true)
{
reply = JOptionPane.showInputDialog(dialog, textMessage);
  
if(reply != int) <- red line showing
System.out.println("Please enter an integer");
else if(reply == int) <- red line showing
{
System.out.println("reply = *" + reply + "*");
break;
}

}

Explanation / Answer

{
JOptionPane dialog;
dialog = new JOptionPane ();
String textMessage = "Please enter an Integer:";
String reply = "";
  
while(true)
{
reply = JOptionPane.showInputDialog(dialog, textMessage);
  
if(!reply.isNumeric())
System.out.println("Please enter an integer");
else if(reply.isNumeric())
{
System.out.println("reply = *" + reply + "*");
break;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote