I’m supposed to develop an algorithm to determine what mortgage rate is
available based on the type and duration of the mortgage desired. This is what I currently have:
import javax.swing.JOptionPane;
String inputX;
inputX=JOptionPane.showInputDialog("Please enter the type of mortgage you would like (e.g. open or closed): ");
String inputY;
inputY=JOptionPane.showInputDialog("Please enter the term duration of your mortage (e.g. 1 yr): ");
if (inputX == "open")
{
if (inputY == "1 yr")
{
println("7.10%");
}
else if (inputY == "3 yr")
{
println("7.50%");
}
else if (inputY == "5 yr")
{
println("Not Available");
}
else
{
println("invalid term duration");
}
}
if (inputX == "closed")
{
if (inputY == "1 yr")
{
println("5.30%");
}
else if (inputY == "3 yr")
{
println("5.00%");
}
else if (inputY == "5 yr")
{
println("5.75%");
}
else {
println("invalid term duration");
}
}
else {
println("invalid mortgage type");
}
println("Have a nice day!");
The problem I’m having is that when I run the program and enter in the type of mortgage and duration, no matter what I put in it always prints “invalid mortgage type”. For example, if I were to input “closed” and “1 yr”, two terms which are supposed to print “5.30%”, it doesn’t work. I’m not sure what I’ve done wrong here. Any help would be appreciated!