title: How to pass variables as parameters
body: <p>I have two bits of code</p>
  
  <pre><code>Tree tree;
  
  void setup() {
    int SZ = 512;  // screen size
  
    int d = 2;
    int x = SZ/2;
    int y = SZ;
  
    size(SZ,SZ);
    background(255);
    noLoop();
  
    tree = new Tree(d, x, y);  
  }
  
  void draw() {
    tree.draw();
  }
  </code></pre>
  
  <p>and also</p>
  
  <pre><code>class Tree {
  
    // member variables
    int    m_lineLength;       // turtle line length
    int    m_x;                // initial x position
    int    m_y;                // initial y position
    float  m_branchAngle;      // turtle rotation at branch
    float  m_initOrientation;  // initial orientation
    String m_state;            // initial state
    float  m_scaleFactor;      // branch scale factor
    String m_F_rule;           // F-rule substitution
    String m_H_rule;           // H-rule substitution
    String m_f_rule;           // f-rule substitution
    int    m_numIterations;    // number of times to substitute
  
    // constructor
    // (d = line length, x &amp; y = start position of drawing)
    Tree(int d, int x, int y) {
      m_lineLength = d;
      m_x = x;
      m_y = y; 
      m_branchAngle = (25.7/180.0)*PI;
      m_initOrientation = -HALF_PI;
      m_scaleFactor = 1;
      m_state = "F";
      m_F_rule = "F[+F]F[-F]F";
      m_H_rule = "";
      m_f_rule = "";
      m_numIterations = 5;
  
      // Perform L rounds of substitutions on the initial state
      for (int k=0; k &lt; m_numIterations; k++) {
        m_state = substitute(m_state);
      }
    }
  
    void draw() {
      pushMatrix();
      pushStyle();
  
      stroke(0);
      translate(m_x, m_y);        // initial position
      rotate(m_initOrientation);  // initial rotation
  
      // now walk along the state string, executing the
      // corresponding turtle command for each character
      for (int i=0; i &lt; m_state.length(); i++) {
        turtle(m_state.charAt(i));
      }
  
      popStyle();
      popMatrix();
    }
  
    // Turtle command definitions for each character in our alphabet
    void turtle(char c) {
      switch(c) {
      case 'F': // drop through to next case
      case 'H':
        line(0, 0, m_lineLength, 0);
        translate(m_lineLength, 0);
        break;
      case 'f':
        translate(m_lineLength, 0);
        break;
      case 's':
        scale(m_scaleFactor);
        break;
      case '-':
        rotate(m_branchAngle);
        break;
      case '+':
        rotate(-m_branchAngle);
        break;
      case '[':
        pushMatrix();
        break;
      case ']':
        popMatrix();
        break;
      default:
        println("Bad character: " + c);
        exit();
      }
    }
  
    // apply substitution rules to string s and return the resulting string
    String substitute(String s) {
      String newState = new String();
      for (int j=0; j &lt; s.length(); j++) {
        switch (s.charAt(j)) {
        case 'F':
          newState += m_F_rule;
          break;
        case 'H':
          newState += m_F_rule;
          break;
        case 'f':
          newState += m_f_rule;
          break;
        default:
          newState += s.charAt(j);
        }
      }
      return newState;
    }
  
  }
  </code></pre>
  
  <p>This isn't assessed homework, it's an end of chapter exercise but I'm very stuck. </p>
  
  <p>I want to "extend the Tree constructor so that values for all of the Tree member variables can be passed in as parameters."</p>
  
  <p>Whilst I understand what variables and parameters are, I'm very stuck as to what to begin reading / where to begin editing the code.</p>
  
  <p>One thing that has confused me and made me question my understanding is that, if I change the constructor values, (for example m_numiterations = 10;), the output when the code is run is the same.</p>
  
  <p>Any pointers in the right direction would be greatly appreciated.</p>