Created
May 10, 2017 06:48
-
-
Save dgadiraju/0abaacb41474edc611b8a51fc18de138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Created by itversity on 10/05/17. | |
| */ | |
| class Fraction(val n: Int, val d: Int) { | |
| override def toString = n + "/" + d | |
| def result = n/d.toDouble | |
| def +(f: Fraction) = { | |
| new Fraction(((n*f.d) + (f.n*d)), (d * f.d)) | |
| } | |
| } | |
| object Fraction { | |
| def main(args: Array[String]): Unit = { | |
| val f = new Fraction(2, 4) | |
| println(f) | |
| println(f.result) | |
| val s = new Fraction(5, 3) | |
| println(s) | |
| println(s.result) | |
| val r = f + s | |
| println(r) | |
| println(r.result) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment