Commit 67b8cf6d authored by Marek Šabo's avatar Marek Šabo
Browse files

Add new file

parents
Loading
Loading
Loading
Loading

3-cviko.kt

0 → 100644
+35 −0
Original line number Diff line number Diff line
import kotlin.math.sqrt

fun main(args: Array<String>) {
    val p1 = Point(3, 4)
    val c = Circle(Point(0,0), 5f)
    println(c.isInCircle(p1))
}

///////////////////////////////////////////////////

/// 1
class Point(var x: Int, var y: Int) {
    override fun toString(): String {
        return "[$x, $y]"
    }

/// 2
    fun move(otherPoint: Point) {
        x += otherPoint.x
        y += otherPoint.y
    }
/// 3
	fun distance(otherPoint: Point): Float {
        var diffX = x - otherPoint.x
        var diffY = y - otherPoint.y
        return sqrt((diffX * diffX + diffY * diffY).toFloat())
    }
}
/// 4
class Circle(val center: Point, val radius: Float) {
    fun isInCircle(p: Point): Boolean {
        return center.distance(p) <= radius
    }
}