模拟图形绘制
case class Point(var x:Double,var y:Double) extends Drawable{
def shift(deltaX:Double,deltaY:Double){x+=deltaX;y+=deltaY}
}
trait Drawable{
def draw(){println(this.toString)}
}
// 请完成 Shape 类、Line 类和 Circle 类的定义。
object MyDraw{
def main(args: Array[String]) {
val p=new Point(10,30)
p.draw;
val line1 = new Line(Point(0,0),Point(20,20))
line1.draw
line1.moveTo(Point(5,5)) //移动到一个新的点
line1.draw
line1.zoom(2) //放大两倍
line1.draw
val cir= new Circle(Point(10,10),5)
cir.draw
cir.moveTo(Point(30,20))
cir.draw
cir.zoom(0.5)
cir.draw
}
}
编译运行程序,期望的输出结果如下:
Point(10.0,30.0)
Line:(0.0,0.0)--(20.0,20.0)
Line:(5.0,5.0)--(25.0,25.0)
Line:(-5.0,-5.0)--(35.0,35.0)
Circle center:(10.0
假期五
原文:https://www.cnblogs.com/jbwen/p/12267078.html