package level02
object Class05 {
class Point(var x: Double, var y: Double) {
def getDist(): Double = {
Math.sqrt(x * x + y * y)
}
def getDist(other: Point): Double = {
val dx = other.x - x
val dy = other.y - y
Math.sqrt(dx * dx + dy * dy)
}
override def toString: String = s"Point($x, $y)"
override def equals(obj: Any): Boolean = {
obj match {
case p: Point => x == p.x && y == p.y
case _ => false
}
}
override def hashCode(): Int = (x, y).hashCode()
}
class LabelPoint(x: Double, y: Double, val label: String) extends Point(x, y)
def main(args: Array[String]): Unit = {
val p1 = new Point(0, 3.0)
val p2 = new Point(0, 1.0)
println(p1.getDist())
println(p2.getDist())
println(p1.getDist(p2))
println(p1)
println(p2)
val lp = new LabelPoint(2.0, 5.0, "A")
println(lp)
println(lp.label)
}
}