title: Function evaluates to true, but using function as parameter of if-statement shows false
body: <p>I have an assignment that calls for creating a person object. </p>
  
  <pre><code>    class Person {
          private String name;
          public Person parent1 = null;
          public Person parent2 = null;
          public Person spouse = null;
          public int numChildren = 0;
          public LinkedList&lt;Person&gt; children = new LinkedList&lt;Person&gt;();
  
          public Person(String n) {
              name = n;
              numChildren = 0;
          }
  </code></pre>
  
  <p>Three functions of my program, M, Y, and Z, do the following: </p>
  
  <p>M — Marry the two people.</p>
  
  <pre><code>        public static void M(String name, String name2) {
              if (findPerson(name).getSpouse() != null &amp;&amp; findPerson(name).getSpouse().getName().equals(name2))
                  System.out.println(name + " and " + name2 + "are already married.");
              else if (Y(name, name2) || Z(name, name2) || Z(name2, name))
                  System.out.println("Unable to complete action. " + name + " and " + name2 + " are related.");
              else if (findPerson(name).spouse != null)
                  System.out.println(findPerson(name).getName() + " is already married.");
              else if (findPerson(name2).spouse != null)
                  System.out.println(findPerson(name2).getName() + " is already married.");
              else
                  findPerson(name).marry(findPerson(name2));
          }
  </code></pre>
  
  <p>Y — States whether name2 is an ancestor of name1.</p>
  
  <pre><code>        public static boolean Y(String name, String name2) {
              if (name.equals(name2))
                  return true;    
              else if (findPerson(name).getParent1() != null)
                  Y(findPerson(name).getParent1().getName(), name2);
              else if (findPerson(name).getParent2() != null)
                  Y(findPerson(name).getParent2().getName(), name2);
              else if (findPerson(name2).getParent1() != null)
                  Y(findPerson(name2).getParent1().getName(), name);
              else if (findPerson(name2).getParent2() != null)
                  Y(findPerson(name2).getParent2().getName(), name);
              return false;
          }
  </code></pre>
  
  <p>Z — States whether name2 is a descendant of name1.</p>
  
  <pre><code>        public static boolean Z(String name, String name2) {
  
              LinkedList&lt;Person&gt; c1 = findPerson(name).getChildren();
  
              for (int i = 0; i &lt; findPerson(name).getNumChildren(); i++) {
                  if (c1.get(i).getName().equals(name2))
                      return true;
                  else if (c1.get(i).getNumChildren() != 0)
                      if (Z((c1.get(i).getChildren().get(0).getName()), name2))
                          return true;
              }
              return false;
          }
  </code></pre>
  
  <p>I use Y and Z to determine if name and name2 are related in any way. If they are, then in the function M, the second if statement prints out a message end exits the function.</p>
  
  <p>Other related functions:<br>
  P — Record that name is a parent of name2.<br>
  T — Print out the tree of descendants of the specified person.</p>
  
  <p>An example of a test input I've been working with:</p>
  
  <pre><code>    O Jon  
      O Jane  
      O Daniel  
      O Kevin  
      O Atticus  
      P Atticus Jon  
      P Atticus Jane  
      P Jon Daniel  
      P Jane Kevin  
      T Atticus
  
      Atticus
          |----&gt;Jon
          |       |---&gt;Daniel
          |----&gt;Jane
                  |---&gt;Kevin
  </code></pre>
  
  <p>However, when I try to call M(Daniel, Kevin) it marries them, even though they're related (they would be cousins).  </p>
  
  <p>I input the line of code:</p>
  
  <pre><code>    System.out.println(name + ", " + name2);
  </code></pre>
  
  <p>at the top of the function Y; for the sample input above, the output is:</p>
  
  <pre><code>    Daniel, Kevin
      Jon, Kevin
      Atticus, Kevin
      Jane, Atticus
      Atticus, Atticus
  </code></pre>
  
  <p>So it's finding that Daniel and Kevin share a grandfather, Atticus.</p>
  
  <p>I did a similar print statement and verified that my function was evaluating to true for this input, since the first thing Y checks is if name.equals(name2), in other words, ("Atticus").equals("Atticus").  </p>
  
  <p>But it's not triggering the second if-statement in M, and I don't know why. Am I missing something really simple?</p>
  
  <p>If you'd like to see the rest of my code, let me know and I'll make an edit.</p>