Last active
August 8, 2019 19:09
-
-
Save fboeller/57295c2bd2089c229cf09f9297b5e8a1 to your computer and use it in GitHub Desktop.
This file contains 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
interface Shape { | |
fun perimeter(): Double | |
fun area(): Double | |
fun diameter(): Double | |
} | |
class Rectangle(val x: Double, val y: Double) : Shape { | |
override fun perimeter() = (x + y) * 2 | |
override fun area() = x * y | |
override fun diameter() = Math.sqrt(x * x + y * y) | |
} | |
class Circle(val radius: Double) : Shape { | |
override fun perimeter() = 2 * PI * radius | |
override fun area() = PI * radius * radius | |
override fun diameter() = 2 * radius | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment