spark学习——实验二完成

  几天完成了实验二,将实验二Scala的相关内容完成了一下,涉及到Scala语言的相关函数的用法等,涉及到很多,明天完成实验三hdfs的内容,实验三的内容之前就了解过所以说明天抓紧应该可以写到实验四,尽快完成spark的相关实验,将实验报告整理出来,完成相关的爬取数据的大作业工作。

package ch.Tutorial2


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)}
}
trait Shape{
  def moveTo(point:Point)
  def zoom(a:Double)
  def draw(){println(this.toString)}
}
case class Line(val point:Point,val point2:Point) extends Shape{
  def  moveTo(shift:Point){
    point.x+=shift.x
    point.y+=shift.y
    point2.x+=shift.x
    point2.y+=shift.y
  }
  def zoom(a:Double){
    var length=point2.x-point.x
    var length2=length*a
    point.x-=(length2-length)/2
    point.y-=(length2-length)/2
    point2.x+=(length2-length)/2
    point2.y+=(length2-length)/2
  }
}
case class Circle(val point:Point,var redit:Double)extends Shape {
  def moveTo(delta:Point){
      point.x+=delta.x
      point.y+=delta.y
  }
  def zoom(a:Double){
    redit=redit*a
  }
}
object exercise2_2 {
  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
   }
}

 

posted @ 2020-02-09 19:08  九离  阅读(287)  评论(0编辑  收藏  举报