Algorithms and OOD (CSC 207 2014F) : EBoards

CSC207.01 2014F, Class 07: Classes and Objects, Revisited


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

Questions

Thinking in Objects

Naming Conventions

Additional Issues/Questions

More Fun with Fractions

What might be wrong with this code?

    public class Fraction
    {
      BigInteger num;
      BigInteger denom;

      public Fraction(BigInteger num, BigInteger denom)
        throws ZeroDenominatorException
      {
        this.num = num;
        this.denom = denom;
      } // Fraction(BigInteger, BigInteger)

      public Fraction add(Fraction that)
      {
        // a/b + c/d = (ad+bc)/bd
        BigInteger resultNumerator = 
          this.num.multiply(that.denom).add(this.denom.multiply(that.num));
        BigInteger resultDenominator = 
          this.denom.multiply(that.denom);
        return new Fraction(resultNumerator, resultDenominator);
      } // add(Fraction)
    } // class Fraction

Lab