Need help please (student programmer).

Hi all. I was wondering if anyone can give me a solution to my problem.
I will 1st print my source code and then refer you to my problem...
     Assignment 2:     Chapter 4
     Programmer:          Yucca Nel
     Date:               28 November 2007
     Filename:          MyType.java
     Purpose     :          This Program helps beginner java programmers better understand java data types.
import java.io.*;
import javax.swing.JOptionPane;
public class MyTypeSwing
public static void main(String[] args) throws IOException
     // Declare variables
     String strChoice, strTryString, strTryInt, strTryDouble;
     int choice, tryInt;
     double tryDouble;
     boolean done = false;
     //loop
     while(!done)
          try
          strChoice = JOptionPane.showInputDialog(null,"Whats My Type?\n\n1)String\n2)integer\n3)double\n4)Quit the program");
          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");
                    break;
               case 3:
                    JOptionPane.showMessageDialog(null,"Correct");
                    break;
               case 4:
                    done = true;
                    JOptionPane.showMessageDialog(null,"Program will now close");
                    break;
               default:
               throw new NumberFormatException();
          catch(NumberFormatException e)
               JOptionPane.showMessageDialog(null,"You must enter a 1, 2, 3, or 4 ","Error",JOptionPane.INFORMATION_MESSAGE);
now for the problem. The exercise I am doing requests me to include the following:
1) I need to parse the value to tryInt in case 2:
2) Likewise in case 3: I need to parse the value to tryDouble
the problem I have is that as you will see I have declared all variables and I am not allowed to declare them again within the switch statement. According to the exercise nothing more needs to be done to the application, meaning that there were no instructions on anything else needed to be done. According to the instructions I am 100% sure that I need to do 1) and 2) within the switch(choice) I am so stuck and I would appreciate help.

No the instruction is as follows....
1. Type a class header and an opening brace to begin class.
2. Type public static void main(String[] args) and an opening brace to begin the main() method header
3. Declare the following variables using the code:
String strChoice, strTryString, strTryInt, strTryDouble;
int choice, tryInt;
double tryDouble;
boolean done = false;
4. Begin a while(!done) loop to repeat as long as the user does not click the cancel button.
5. Inside a try statement, enter code to display an input box as shown in figure (THIS IS CORRECT)
6.Type choice = Integer.parseInt(strChoice); on the next line to parse the value for the choice entered by the user.
7.Create a switch statement to test for each of the three choices. Type switch(choice) as the header and then press the ENTER key. Type an opening brace.
8.Enter a cas statement for each of the 3 choices using pages (blah blah) as a guide (did that), for coding the switch, case and break statements.
-case1: If the user enters 1, Display a message to inform users that they are correct, as any data can be saved as a string.
-case2: If the user enters 2, ***************where i have a problem*********************parse the value into tryInt.Display message.
etc. etc. It states that I need to do the parse within that specific point. Please help.

Similar Messages

Maybe you are looking for