summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Scala/sandbox/3-rationals.scala14
1 files changed, 7 insertions, 7 deletions
diff --git a/Scala/sandbox/3-rationals.scala b/Scala/sandbox/3-rationals.scala
index 8cdf4d7..d1eda22 100644
--- a/Scala/sandbox/3-rationals.scala
+++ b/Scala/sandbox/3-rationals.scala
@@ -14,18 +14,18 @@ object Rationals {
def numer = x / g
def denom = y / g
- def neg = new Rational(-numer, denom)
+ def unary_- = new Rational(-numer, denom)
- def less(that: Rational) = this.numer * that.denom < that.numer * this.denom
+ def < (that: Rational) = this.numer * that.denom < that.numer * this.denom
- def max(that: Rational) = if (this.less(that)) that else this
+ def max(that: Rational) = if (this < (that)) that else this
- def add(that: Rational) =
+ def + (that: Rational) =
new Rational(
numer * that.denom + that.numer * denom,
denom * that.denom)
- def sub(that: Rational) = add(that.neg)
+ def - (that: Rational) = this + -that
override def toString = numer + "/" + denom
@@ -33,8 +33,8 @@ object Rationals {
def run = {
println("Rationals")
- println(new Rational(2, 3) add (new Rational(3, 4)) toString)
- println(new Rational(1, 3) sub (new Rational(5 ,7)) sub (new Rational(3, 2)) toString)
+ println(new Rational(2, 3) + (new Rational(3, 4)) toString)
+ println(new Rational(1, 3) - (new Rational(5 ,7)) - (new Rational(3, 2)) toString)
println(new Rational(1, 3) max (new Rational(5 ,7)) toString)
}