zoukankan      html  css  js  c++  java
  • 假期五

    模拟图形绘制
     
    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
  • 相关阅读:
    day_07 深浅拷贝
    day_06 再谈编码
    day_05 字典
    day_04 列表
    day_03 字符串
    HDU 1049 Climbing Worm
    HDU 1720 A+B Coming
    Pascal向C++的跨越
    B-Boxes
    喵哈哈村的狼人杀大战(4)
  • 原文地址:https://www.cnblogs.com/jbwen/p/12267078.html
Copyright © 2011-2022 走看看