title: Updating instance variable values and ensuring private methods use them - Java
body: <p>I have constructed a class that will compute an equation based on private instance variables.</p>
  
  <p>These variables may be updated using getter and setter methods, the latter of which are called and changed from a separate control class within the project (I am using Eclipse if that is relavant)</p>
  
  <p>I need to ensure that the constructor uses the updated values when passed from the separate control class to the setter methods in computing variable c.</p>
  
  <p>Here is snipets of my code.</p>
  
  <p>instance variables</p>
  
  <pre><code>    private double a;
      private double b; 
      private double c;
  </code></pre>
  
  <p>constructor</p>
  
  <pre><code>public Prob(){
      a = 4; //must be first initialized with these values then later changed from the control class
      b = 10;
      setA(a);
      setB(b);
      setC();
  </code></pre>
  
  <p>setter methods</p>
  
  <pre><code>public void setA(double a){
      if(isValidA(a))
          this.a = a;
      else this.a = 100; // 100 is meaningless and allows execution of "invalid" string
              }
  public void setB(double b){
      if(isValidB(b))
          this.b = b;
      else this.b = -1; // -1 is meaningless, allows execution "invalid entry" code in string
          }
  
  private void setC(){
          if(a&lt;=5 &amp;&amp; b&gt;=2)
               c = (int)(5 + 0.5*a - 5*(Math.pow(b, 0.2)) + 0.5*(a)*b;
         else c = a; 
  }
  </code></pre>
  
  <p>I can update variable a or variable b from the control class but how can I get variable c to update as well based on the current a and b?</p>