# What;s wrong with my code? SOS assignment help

**URL:** <https://discourse.processing.org/t/what-s-wrong-with-my-code-sos-assignment-help/4301>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 9, 2018, 10:01pm UTC](https://discourse.processing.org/t/what-s-wrong-with-my-code-sos-assignment-help/4301 "2018-10-09T22:01:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![njdsvdsjVNsdo](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@njdsvdsjVNsdo](https://discourse.processing.org/u/njdsvdsjVNsdo)\
**Post date:** [October 9, 2018, 10:01pm UTC](https://discourse.processing.org/t/what-s-wrong-with-my-code-sos-assignment-help/4301/1 "2018-10-09T22:01:56Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 9, 2018, 10:18pm UTC](https://discourse.processing.org/t/what-s-wrong-with-my-code-sos-assignment-help/4301/2 "2018-10-09T22:18:37Z")

</div>

- [Processing.org/reference/String\_equals\_.html](http://Processing.org/reference/String_equals_.html)
- [Forum.Processing.org/two/discussion/12532/windowjs-cross-mode-alert-confirm-prompt-other-js-api-for-java](http://Forum.Processing.org/two/discussion/12532/windowjs-cross-mode-alert-confirm-prompt-other-js-api-for-java)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 10, 2018, 1:46am UTC](https://discourse.processing.org/t/what-s-wrong-with-my-code-sos-assignment-help/4301/3 "2018-10-10T01:46:42Z")

</div>

yes i see same problem  
-a- a else was missing  
-b- the ( inputX == “open” ) seems not to work  
but with  
a.contentEquals(b)  
it worked  
-c- possibly use a selection list

```auto
import javax.swing.JOptionPane;
final String[] select1 = { "open", "closed"};
final String[] select2 = { "1 yr", "3 yr", "5 yr"};

String inputX;
inputX= (String) JOptionPane.showInputDialog(frame, "type of mortgage you would like: ", "select string", JOptionPane.QUESTION_MESSAGE, null, select1, select1[0]);
String inputY;
inputY= (String) JOptionPane.showInputDialog(frame, "term duration of your mortage: ", "select string", JOptionPane.QUESTION_MESSAGE, null, select2, select2[0]);

if (true) {
  print("inputX_");
  print(inputX);
  print("_inputY_");
  print(inputY);
  println("_");
}

if (inputX.contentEquals("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");
  }
} else if (inputX.contentEquals("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!");

```
