I am in my first year of Java programming and I am having a hard time. I have been working on a small program and probably have more than one mistake. My instructor told me to check where the try clause ends. I have no idea.
I am new posting here so I am not sure if this will work. I hope you can copy and paste into a textpad file.
Please please help.
Thanks so much
I am new posting here so I am not sure if this will work. I hope you can copy and paste into a textpad file.
Please please help.
Thanks so much
Code:
import javax.swing.JOptionPane;
public class MyType
{
public static void main(String[] args)
{
// declare and construct variables
String strChoice, strTryString, strTryInt, strTryDouble;
int choice, tryInt;
double tryDouble;
boolean done = false;
// loop while user does not click cancel button
while(!done)
{
try
{
JOptionPane.showInputDialog(null,"What's My Type?\n1)String\n2)integer\n3)double\n4Quit the program\n");
choice = Integer.parseInt(strChoice);
}
switch(choice)
{
case 1:
JOptionPane.showMessageDialog(null, "Correct, any input can be saved as a String");
break;
case 2:
JOptionPane.showMessageDialog(null, "Correct");
tryInt = Integer.parseInt(strChoice);
break;
case 3:
JOptionPane.showMessageDialog(null, "Correct");
tryDouble = Integer.parseInt(strChoice);
break;
case 4:
done = true;
JOptionPane.showMessageDialog(null, "Now Closing");
break;
default:
throw new NumberFormatException();
}
}
}
catch(NumberFormatException e);
{
JOptionPane.showMessageDialog(null, "Please try again");
}
}
System.exit(0);
}
}
Comment