title: How to write an .add() method?
body: <p>this is a homework problem, and I am having trouble understanding how I can create a .add() method in a class Distance.</p>
  
  <p>class Distance has two integer instance variables:</p>
  
  <pre><code>private int feet;
  private int inches;
  </code></pre>
  
  <p>It has a no argument constructor that initializes a Distance with zero feet and zero inches.</p>
  
  <p>It has a two argument constructor that accepts two positive integers for feet and inches, and throws and exception if they are negative or if inches is greater than 11.</p>
  
  <p>It also has get/set methods for the instance variables. My get/set methods:</p>
  
  <pre><code>public void setFeet(int f){
      feet = f;
  }
  
  public void setInches(int in){
      inches = in;
  }
  
  public int getFeet(){
      return feet;
  }
  
  public int getInches(){
      return inches;
  }
  </code></pre>
  
  <p>My first question to anyone willing to answer: Is this how I am supposed to set up these get/set methods? I am unsure of myself.</p>
  
  <p>My second problem lies with creating a method add() that adds another Distance object to itself. That is, </p>
  
  <pre><code>w1 = new Distance(4,9);
  w2 = new Distance(3,6);
  w1.add(w2); //w1 becomes 8 feet, 3 inches.
  </code></pre>
  
  <p>So far, I have this:</p>
  
  <pre><code>    public int add(Distance d) {
      int df = d.getFeet();
      int di = d.getInches();
      int a = this.feet;
      int b = this.inches;
      int c = a.getFeet();
      int d = b.getInches();
      int sumInches, sumFeet, temp;
      sumInches =di + d;
      sumFeet = df + c;
      if (sumInches&gt;11) {
          temp = sumInches-11;
          sumFeet = sumFeet+1;
          sumInches = temp;
      }
      this.feet = sumFeet;
      this.inches = sumInches;
  }
  </code></pre>
  
  <p>But I am unsure if this would even compile (I don't have access to a computer where I can install a compiler right now). Can someone examine this and explain to me why this might be wrong?</p>