title: Homework: Magic Plant Recursion Exercise in Java
body: <p>To make it clear, this IS a graded assignment for my Programming II class. I've generally been very easily receptive to new programming concepts but this particular assignment on recursion is really throwing me and I'm looking for some good nudging in the right direction. Below is the assignment verbatim and the code I currently already have.</p>
  
  <p><strong>Magic Plant</strong></p>
  
  <p>We have a magic plant that once it is planted, it germinates and grows two leaves in the first year. It doubles its leaves every year except that every three years it triples its leaves. Something like:</p>
  
  <p><img src="https://i.stack.imgur.com/qiCyQ.png" alt="Link to table displayed in my homework document">
  <br></p>
  
  <p>Write a class called MagicPlant that includes the following methods:</p>
  
  <ul>
  <li>A method that returns the number of leaves given the age of the plant</li>
  <li>A non-recursive method that returns the age of the plant given the number of leaves.</li>
  <li>A recursive method that returns the age of the plant given the number of leaves.</li>
  </ul>
  
  <p>In a driver class test the methods.</p>
  
  <p>Find out what is the largest (oldest) plant that your algorithm and data structure can handle.</p>
  
  <hr>
  
  <p>That is what I was given and I'm having trouble on the last bullet point as well as a bit muddy on the second one (but I have code that seems to work).</p>
  
  <p>My current code excluding the Driver class since it's just call statements:</p>
  
  <pre><code>public class MagicPlant {
  
      // Method that returns the number of leaves given
      // the age of the plant.
      public int getLeaves(int age) {
          int leafCount = 1;
          for (int i = 1; i &lt;= age; i++) {
              if (i % 3 != 0) {
                  leafCount *= 2;
              } else {
                  leafCount *= 3;
              }
          }
          return leafCount;
      }
  
      // Non-recursive method that returns the age of the plant
      // given the number of leaves.
      public int getAgeNR(int leaves) {
          int age = 1;
          while (leaves &gt; getLeaves(age)) {
              age++;
          }
          return age;
      }
  
      // Recursive method that returns the age of the plant
      // given the number of leaves.
      public int getAgeR(int leaves) {
          return 0;
      }
  }
  </code></pre>