Square.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: mrs
  5. * Date: 28.12.2017
  6. * Time: 11:06
  7. */
  8. require_once('InterfacePerimeter.php');
  9. require_once('AbstractArea.php');
  10. class Square extends Area implements Perimeter
  11. {
  12. public $diagonalLength;
  13. public $segmentLength;
  14. public $perimeter;
  15. public $area;
  16. public function __construct(float $diagonalLength)
  17. {
  18. $this->diagonalLength = $diagonalLength;
  19. }
  20. public function getSegmentLength(): float
  21. {
  22. $this->segmentLength = ($this->diagonalLength) / sqrt(2);
  23. return $this->getSegmentLength();
  24. }
  25. public function printSegmentLength(): void
  26. {
  27. if (empty($this->segmentLength)) {
  28. $this->getSegmentLength();
  29. }
  30. echo "Длина стороны квадрата равна " . $this->segmentLength;
  31. }
  32. public function getArea(): float
  33. {
  34. $this->area = ($this->segmentLength) ** 2;
  35. return $this->getArea();
  36. }
  37. public function printArea(): void
  38. {
  39. if (empty($this->area)) {
  40. $this->getArea();
  41. }
  42. echo "Площадь квадрата равна " . $this->area;
  43. }
  44. public function getPerimeter(): float
  45. {
  46. $this->perimeter = 4 * ($this->segmentLength);
  47. return $this->getPerimeter();
  48. }
  49. public function printPerimeter(): void
  50. {
  51. if (empty($this->perimeter)) {
  52. $this->getPerimeter();
  53. }
  54. echo "Периметр квадрата равен " . $this->perimeter;
  55. }
  56. }