|
@@ -0,0 +1,69 @@
|
|
|
+<?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;
|
|
|
+ }
|
|
|
+}
|