Im trying to make it so that my menu options that i've highlighted are their own method but i was having issues with returning them so i could use the selection as an int for my switch statement.Any ideas?
import javax.swing.JOptionPane;
public class ConversionProgram {
/**
* @param args
*/
public static void main(String[] args) {
String input;
String selection;
int choice =0;
int meters;
input=JOptionPane.showInputDialog("Enter the distance in meters : ");
meters=Integer.parseInt(input);
while (choice != 4){
[U]selection = JOptionPane.showInputDialog("1. Convert to kilometers \n 2. Convert to inches" +
"\n" + "3. Convert to feet" + "\n" + "4. Quit the program");
choice = Integer.parseInt(selection);[/U]
switch(choice){
case '1' :
showKilometers(meters);
break;
case '2' :
showInches(meters);
break;
case '3' :
showFeet(meters);
break;
case '4' :
System.exit(0);
default: JOptionPane.showMessageDialog(null, "Invalid number");
}
}
}
// Converts meters into feet
public static void showFeet(int meters) {
double feet = meters*3.281;
JOptionPane.showMessageDialog(null, feet);
}
public static void showInches(int meters) {
// TODO Auto-generated method stub
double inches = meters*39.37;
JOptionPane.showMessageDialog(null, inches);
}
public static void showKilometers(int meters) {
double kilometers = meters*.001;
JOptionPane.showMessageDialog(null, kilometers);
// TODO Auto-generated method stub
}
}