First off I must say that I suck at methods and do not understand them at all. I have the beginning where it asks for the miles or inches but when I choose one of the options it brings up the miles conversion. This is the code that I have so far. Can someone help me with the methods that will switch between the miles and the inches.
import javax.swing.*;
public class temp1
{
public static void main(String [] args)
{
String fstring;
double miles,km;
boolean notdone = true;
int YESorNO;
int MorI;
double inches, centimeter;
//Get UI as string input
while(notdone)
{
JOptionPane.showInputDialog(null, "Would you like to convert mi to km or in to cm?");
fstring = JOptionPane.showInputDialog(null, "Enter Miles:");
//Convert UI to double
miles = Double.parseDouble(fstring);
//Calculate Celsius
km = (int) (miles * 1.609344f);
//User Message
JOptionPane.showMessageDialog(null, "Miles Entered" + miles +"Kilometers " +km, "Miles to Kilometers", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showInputDialog(null, "Enter Inches:");
//Convert inches to centimeters
inches = Double.parseDouble(fstring);
centimeter = (int) (inches * 2.54f);
JOptionPane.showMessageDialog(null, "Inches Entered" + inches + "Centimeters" +centimeter, "Inches to Centimeters", JOptionPane.INFORMATION_MESSAGE);
//Yes_No Window
YESorNO = JOptionPane.showConfirmDialog(null, "End Program", "Message", JOptionPane.YES_NO_OPTION);
if(YESorNO == JOptionPane.YES_OPTION)
{
System.exit(0);
notdone = false;
}//end if
}//end while
}//end main
}//end class


Sign In
Create Account


Back to top










