TUTORIAL 1 Step 1 RationalNumber.scala - - - class RationalNumber(num: Int, den: Int) { var numerator = num var denominator = den } Step 2 RationalNumber.scala - - - class RationalNumber(num: Int, den: Int) { var numerator = num var denominator = den override def toString () = numerator+"/"+denominator } Step 3 RationalNumber.scala - - - class RationalNumber(num: Int, den: Int) { var numerator = num var denominator = den def gcd (x:Int,y:Int) : Int= { if (y==0) x else gcd(y,x%y) } override def toString () = numerator+"/"+denominator } Step 4 RationalNumber.scala - - - class RationalNumber(num: Int, den: Int) { private[this] var _numerator = num private[this] var _denominator = den private[this] var _lcd = 0 reduce() def gcd (x:Int,y:Int) : Int = { if (y==0) x else gcd(y,x%y) } private def setDenominator(newD: Int) { this._denominator = newD} private def setNumerator(newN: Int) { this._numerator = newN} def reduce () = { this._lcd = gcd(this._numerator,this._denominator) setDenominator(this._denominator / this._lcd) setNumerator(this._numerator / this._lcd) } override def toString () = _numerator+"/"+_denominator } TUTORIAL 2 Step 1 RationalNumber.scala - - - class RationalNumber(num: Int, den: Int) { private[this] var _numerator = num private[this] var _denominator = den private[this] var _lcd = 0 reduce() def gcd (x:Int,y:Int) : Int = { if (y==0) x else gcd(y,x%y) } private def setDenominator(newD: Int) { this._denominator = newD} private def setNumerator(newN: Int) { this._numerator = newN} def getNumerator[double]() = _numerator def getDenominator[double]() = _denominator def reduce () = { this._lcd = gcd(this._numerator,this._denominator) setDenominator(this._denominator / this._lcd) setNumerator(this._numerator / this._lcd) } override def toString () = _numerator+"/"+_denominator } Step 2 class Grader(upperGrade: Int, lowerGrade: Int) { def getGrades(grades: List[RationalNumber]): Iterable[RationalNumber] = { for (val i <- grades){ if(i > lowerGrade && i < upperGrade) {grades.remove(p)} } } }