123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * Created by PhpStorm.
- * User: mrs
- * Date: 28.12.2017
- * Time: 11:06
- */
- require_once('InterfacePerimeter.php');
- require_once('AbstractArea.php');
- class Square extends Area implements Perimeter
- {
- public $diagonalLength;
- public $segmentLength;
- public $perimeter;
- public $area;
- public function __construct(float $diagonalLength)
- {
- $this->diagonalLength = $diagonalLength;
- }
- public function getSegmentLength(): float
- {
- $this->segmentLength = ($this->diagonalLength) / sqrt(2);
- return $this->getSegmentLength();
- }
- public function printSegmentLength(): void
- {
- if (empty($this->segmentLength)) {
- $this->getSegmentLength();
- }
- echo "Длина стороны квадрата равна " . $this->segmentLength;
- }
- public function getArea(): float
- {
- $this->area = ($this->segmentLength) ** 2;
- return $this->getArea();
- }
- public function printArea(): void
- {
- if (empty($this->area)) {
- $this->getArea();
- }
- echo "Площадь квадрата равна " . $this->area;
- }
- public function getPerimeter(): float
- {
- $this->perimeter = 4 * ($this->segmentLength);
- return $this->getPerimeter();
- }
- public function printPerimeter(): void
- {
- if (empty($this->perimeter)) {
- $this->getPerimeter();
- }
- echo "Периметр квадрата равен " . $this->perimeter;
- }
- }
|