I am new to to programming - and am learning Java. I am trying to work an if/else statement using JOptionPane. Everything works okay, except the statements. I only get the statement "Stop and get gas!" no matter what the answer entered (yes or no).
Any help would be appreciated!
//This program determine if I have to stop for gas on the way in to work.
import javax.swing.JOptionPane;
import java.util.*;
public class GasIndicator
{
public static void main(String[] args)
{
String answer;
String outputStr1;
String outputStr2;
answer =
JOptionPane.showInputDialog ( "Do you have at least an eighth tank of gas? yes or no " );
outputStr1 = "You can drive straight to work";
outputStr2 = "Stop and get gas!";
if (answer == "yes")
JOptionPane.showMessageDialog(null, outputStr1, "Gas", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, outputStr2, "Gas", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}