Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
Never
<?php
class Shape
{
    protected $area;
    protected $perimeter;

    public function getArea()
    {
        return $this->area;
    }
    public function getPerimeter()
    {
        return $this->perimeter;
    }
}
class Triangle extends Shape
{
    private $base;
    private $height;
    private $vatar;

    public function __construct($base, $height, $vatar)
    {
        $this->setSides($base, $height, $vatar);
        $this->area = ($this->base * $this->height) / 2;
        $this->perimeter = $this->base + $this->height + $this->vatar;
    }

    public function setSides($base, $height, $vatar)
    {
        if ($vatar > $base && $vatar > $height) {
            $this->base = $base;
            $this->height = $height;
        }
    }
}




class Square extends Shape
{
    private $side;

    public function __construct($side)
    {
        $this->setSides($side);
        $this->area = $this->side * $this->side;
        $this->perimeter = $this->side * 4;
    }

    public function setSides($side)
    {
        $this->side = $side;
    }
}

class Rectangle extends Shape
{
    private $length;
    private $height;

    public function __construct($length, $height)
    {
        $this->setSides($length, $height);
        $this->area = $this->length * $this->height;
        $this->perimeter = ($this->length + $this->height) * 2;
    }

    public function setSides($length, $height)
    {
        $this->length = $length;
        $this->height = $height;
    }
}



$squ = new Square(2);
echo $squ->getArea();
$rec = new Rectangle(2, 3);
echo $rec->getArea();