{
        return $this->_sideLength;
    }
    public function setSideLength($length)
    {
        $this->_sideLength = $length;
    }
    public function getArea()
    {
        return pow($this->_sideLength, 2);
    }
}
$myCircle = new Circle();
$myCircle->setColor("red");
$myCircle->fill();
$myCircle->setRadius(4);
echo "<h2>My Circle</h2>";
echo "<p>My circle has a radius of " . $myCircle->getRadius() . ".</p>";
echo "<p>It is " . $myCircle->getColor() . " and it is " . ($myCircle->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my circle is: " . $myCircle->getArea() . ".</p>";
$mySquare = new Square();
$mySquare->setColor("green");
$mySquare->makeHollow();
$mySquare->setSideLength(3);
echo "<h2>My Square</h2>";
echo "<p>My square has a side length of " . $mySquare->getSideLength() . ".</p>";
echo "<p>It is " . $mySquare->getColor() . " and it is " . ($mySquare->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my square is: " . $mySquare->getArea() . ".</p>";
?>

  </body>
Ejemplo n.º 2
0
 public function testArea()
 {
     $circle = new Circle();
     $circle->setRadius(10);
     $this->assertEquals(M_PI * pow(10, 2), $circle->getArea());
 }