Hey i am writing some code for a homework problem and am currently writing some exceptions so the program well not crash, but i have ran into a problem.
CODE
case 1:
temp = JOptionPane.showInputDialog("Input a flight number that the person is going to:");
temp1 = JOptionPane.showInputDialog("Input the person's name to be added to the queue:");
pq.addFlight(Integer.parseInt(temp), temp1);
break;
I think this is all the code needed, i declared all my variables earlier and it runs just fine now. However, I want to put a try/catch statement after temp is entered to make sure it is an integer. When i tried to do it, down below at my call pq.addFlight it said temp had not been declared.
Here's how i did it
CODE
case 1:
try{
temp = JOptionPane.showInputDialog("Input a flight number that the person is going to:");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Error: You must enter an integer for the flight number.");
}
temp1 = JOptionPane.showInputDialog("Input the person's name to be added to the queue:");
pq.addFlight(Integer.parseInt(temp), temp1);
break;
Is there a why to get around this? Thanks