-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
I just want to give feedback regarding the "4.1.4.3 Shaping Up 2 (Da Streets)" exercise.
The answer to that exercise gives the wrong result.
sealed trait Rectangular {
def width: Double
def height: Double
val sides = 4
val perimeter = 2*width + 2*height
val area = width*height
}
case class Square(size: Double) extends Rectangular {
val width = size
val height = size
}
case class Rectangle(
val width: Double,
val height: Double
) extends Rectangular
val square = Square(10)
square.perimeter
square.area
square.sides
val rectangle = Rectangle(5, 6)
rectangle.perimeter
rectangle.area
rectangle.sides
I found out that the square's perimeter and area are always returning 0.0
to fix it I changed width and height into def as below.
case class Square(size: Double) extends Rectangular {
def width = size
def height = size
}
zeshansali
Metadata
Metadata
Assignees
Labels
No labels