Skip to content

Instantly share code, notes, and snippets.

@fboeller
Last active August 8, 2019 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fboeller/57295c2bd2089c229cf09f9297b5e8a1 to your computer and use it in GitHub Desktop.
Save fboeller/57295c2bd2089c229cf09f9297b5e8a1 to your computer and use it in GitHub Desktop.
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