JCreator Problem. Please help!
Posted: Sat Apr 17, 2010 8:04 am
Im suppose to make this program for my class. My friend gave me his project and told me to make it look different and submit it to the professor. Here is the project He did on jcreator. is there ANYWAY you can make it look different but function the same thing? it will really help i have 2 more days to submit it.
Code: Select all
import javax.swing.JOptionPane;
public class convert
{
public static void main(String []args)
{
boolean loop = true;
double meters;
String choice;
try {meters = Double.parseDouble(JOptionPane.showInputDialog("Enter a distance in meters"));}
catch (Exception e) {meters = 500;} //try and catch is an exception that your prof will show you later.
while (loop == true)
{
choice = menu();
if (choice.equals("1"))
showInches(meters);
else if (choice.equals("2"))
showFeet(meters);
else if (choice.equals("3"))
showKilometers(meters);
else if (choice.equals("4"))
loop = false;
else
JOptionPane.showMessageDialog(null, "Invalid choice!!!");
}
}
//--------------------------------------------------------------------
public static void showKilometers (double meters)
{
double kilometers;
kilometers = meters * 0.001;
System.out.println(meters + " are equal to " + kilometers);
}
//--------------------------------------------------------------------
public static void showInches (double meters)
{
double inches;
inches = meters * 39.37;
System.out.println(meters + " are equal to " + inches);
}
//--------------------------------------------------------------------
public static void showFeet (double meters)
{
double feet;
feet = meters * 3.281;
System.out.println(meters + " are equal to " + feet);
}
//--------------------------------------------------------------------
public static String menu()
{
String input ;
input = JOptionPane.showInputDialog("1. Convert to inches \n2. Convert to feet \n3. Convert to kilometers \n4. End \nEnter Choice: ");
return input;
}
//--------------------------------------------------------------------
}