title: Rational Class - Unable to Reduce fraction and Divide
body: <p>My Rational Class is supposed to add, subtract, multiply, and divide fractions so when called in the Main Class, it will perform these actions. However, I can't seem to reduce my fractions (gcd) properly to get the right answer and the division method isn't running at all (I get a error message): </p>
  
  <p>Exception in thread "main" java.lang.ArithmeticException: / by zero
      at Rational.division(Project1.java:45)
      at Project1.main(Project1.java:12)</p>
  
  <p>How can I fix these problems? Thanks</p>
  
  <p>public class Project1 {</p>
  
  <pre><code>public static void main(String[] args) {
  
      Rational a = new Rational (6, 12);
      Rational b = new Rational (8, 9);
  
      System.out.println(a + " + " + b + " = " + a.add(b));
      System.out.println(a + " - " + b + " = " + a.subtraction(b));
      System.out.println(a + " * " + b + " = " + a.multiply(b));
      System.out.println(a + " / " + b + " = " + a.division(b));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>class Rational {</p>
  
  <pre><code>private int numerator, denominator;
  
  public Rational(int num, int denom) {
      numerator = num;
      denominator = denom;
  }
  public Rational gcd() {
      while (numerator != denominator)
      {
          if (numerator &gt; denominator)
              numerator = numerator - denominator;
          else
              denominator = denominator - numerator;
      }
      return new Rational(numerator, denominator);
  }
  
  public Rational add(Rational o) {
      return new Rational (numerator + o.numerator, denominator +o.denominator);
  }
  
  public Rational conjugate() {
      return new Rational (numerator, - denominator);
  }
  
  public Rational division(Rational o) {
      return new Rational ((numerator/denominator) / (numerator/denominator), denominator);
  }
  
  public Rational multiply(Rational o) {
      return new Rational (numerator * o.numerator, denominator * o.denominator);
  }
  
  public Rational subtraction(Rational o) {
      return new Rational (numerator - o.numerator, denominator - o.denominator);
  }
  
  public String toString() {
      return (numerator + "/" + denominator);
  }
  </code></pre>
  
  <p>}</p>