Skip to content

Commit 1c54c1f

Browse files
author
mdodsworth
committed
chapter 1 done
1 parent 8b67cb9 commit 1c54c1f

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.class
2+
.*.un~

shapes-actor-script.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import shapes._
2+
3+
ShapeDrawer.start()
4+
5+
ShapeDrawer ! new Square(0.0, 1.0)
6+
ShapeDrawer ! 3.14
7+
ShapeDrawer ! "exit"
8+

shapes-actor.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package shapes
2+
3+
import scala.actors._
4+
import scala.actors.Actor._
5+
6+
object ShapeDrawer extends Actor {
7+
def act() {
8+
loop {
9+
receive {
10+
case s:Shape => s.draw
11+
case "exit" => println("exiting..."); exit
12+
case x:Any => println("Error: Unknown type")
13+
}
14+
}
15+
}
16+
}

shapes.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package shapes
2+
3+
class Point(val x:Double, val y:Double) {
4+
override def toString = "Point(" + x + ", " + y + ")"
5+
}
6+
7+
abstract class Shape {
8+
def draw() :Unit
9+
}
10+
11+
class Square(val height:Double, val width:Double) extends Shape {
12+
override def draw() = println("drawing a square(" + height + ", " + width + ")")
13+
}

0 commit comments

Comments
 (0)