ClinicalMistake
April 2nd, 2007, 08:31 PM
Hey yall. I can't seem to get my if statements to execute. I believe the code to be correct, but somewhere the logic is failing. Any ideas?
import javax.swing.*;
public class Conversions {
public static void main(String args[]) {
String choice, input;
double result;
choice = JOptionPane.showInputDialog(null, "If you would like to convert from feet ot meters or vice versa" +
"\nInput either \"meter\" or \"feet\"");
if(choice=="feet") {
input = JOptionPane.showInputDialog(null, "How many feet would you like to convert to meters?");
result = Double.parseDouble(input) * 3.305;
JOptionPane.showMessageDialog(null, "When converting " +input + "feet, you have " +result + " meters");
}
else if(choice=="meter") {
input = JOptionPane.showInputDialog(null, "How many meters would you like to convert to feet?");
result = Double.parseDouble(input) / 3.305;
JOptionPane.showMessageDialog(null, "When converting " +input + " meters, you have " +result + " feet");
}
System.exit(0);
}
}
import javax.swing.*;
public class Conversions {
public static void main(String args[]) {
String choice, input;
double result;
choice = JOptionPane.showInputDialog(null, "If you would like to convert from feet ot meters or vice versa" +
"\nInput either \"meter\" or \"feet\"");
if(choice=="feet") {
input = JOptionPane.showInputDialog(null, "How many feet would you like to convert to meters?");
result = Double.parseDouble(input) * 3.305;
JOptionPane.showMessageDialog(null, "When converting " +input + "feet, you have " +result + " meters");
}
else if(choice=="meter") {
input = JOptionPane.showInputDialog(null, "How many meters would you like to convert to feet?");
result = Double.parseDouble(input) / 3.305;
JOptionPane.showMessageDialog(null, "When converting " +input + " meters, you have " +result + " feet");
}
System.exit(0);
}
}