class Point {
var x: Double = 0.0
var y: Double = 0.0
def this(x: Double, y: Double) {
this()
this.x = x
this.y = y
}
def distance1(): Double = {
x + y
}
def getDist(): Double = {
val squareSum = x * x + y * y
Math.sqrt(squareSum)
}
def fromPoint(other: Point): Double = {
val dx = x - other.x
val dy = y - other.y
val squareDiff = dx * dx + dy * dy
Math.sqrt(squareDiff)
}
override def toString(): String = {
"Point(" + x + ", " + y + ")"
}
override def equals(other: Any): Boolean = {
if (other.isInstanceOf[Point]) {
val p = other.asInstanceOf[Point]
x == p.x && y == p.y
} else {
false
}
}
}
class LabelPoint extends Point {
var label: String = ""
def this(x: Double, y: Double, label: String) {
this()
this.x = x
this.y = y
this.label = label
}
作业
、.;;gb,j'poforjo'a