Решение 6 задачи ( второй способ )

Предыдущий вариант здесь: http://fkn.ktu10.com/?q=comment/3963#comment-3963

<?php 

class Point
{
    public $x;
    public $y;

    function __construct($x, $y)
    {
        $this->x = $x;
        $this->y = $y;
    }

    function distance(Point $point)
    {
        return sqrt ( pow($this-> x -  $point-> x,2 ) + pow( $this-> y  - $point-> y, 2)   );
    }
}

class Trapezoid
{
    public $A;
    public $B;
    public $C;
    public $D;
    public $perimetr;
    public $s;

    function isEquilateral() 
    {
        if (  $c == true ) {  
            echo "Equilateral <BR>";
        } else  {
            echo "NonEquilateral <BR>";
        }
    }

    function getSquare($s)
    {      
        echo "Square: ",$s,"<BR>" ;         
    }   

    function getPerimeter($perimetr)
    {    
        echo "Perimetr: ",$perimetr,"<BR>" ;
    }
}

  $summaploshad=0;
  $N=3;
  for ( $i = 0; $i < $N; $i++) {
  echo "*********************************<BR>";
  $A = new Point (rand(5,20),rand(5,20));
  $B = new Point (rand(5,20),rand(5,20));
  $C = new Point (rand(5,20),rand(5,20));
  $D = new Point (rand(5,20),rand(5,20));
  echo "AB: ", $A -> distance ($B),"<BR>" ;
  echo  "BC: ", $B -> distance ($C),"<BR>" ;
  echo "DC: ", $C -> distance ($D) ,"<BR>";
  echo  "DA: ",$D -> distance ($A) ,"<BR>";
  $s[$i] = (($D->distance($A)+$B->distance ($C))/2)*sqrt(pow($A ->distance ($B),2)-pow(($D -> distance ($A)-$B -> distance ($C) )/2,2)) ;
  $perimetr =$A->distance ($B)+$B->distance($C)+$C->distance($D)+$D->distance($A);
  $b [$i] = new Trapezoid ();
  $b [$i]-> isEquilateral($A -> distance ($B) == $C -> distance ($D));
  $b [$i]->getPerimeter($perimetr);
  $b [$i]->getSquare($s[$i]);
  $sumsquare += $s[$i];
  } 
   $Averagearea = $sumsquare/$N;
   $k=0;
   for ( $i = 0; $i < $N; $i++) {
     if (  $s[$i] > $Averagearea) {
       $k =$k +1;
    }
   }
    echo "<BR> <BR> <BR> Summa  ploshad:  ", $sumsquare, "<BR>";
    echo $sumsquare, "/",$N, "  Srednya ploshad: ", $Averagearea, "<BR>" ;
    echo "Kolichtstvo trapecii ploshad bolshe srednei: ", $k;
?>

Этот скрипт выполняется с ошибками.

Предлагаю задачу: реализовать метод getLengthOfLineSegment в классе Trapeziod.
getLengthOfLineSegment должен принимать строку -- название отрезка (например AB', 'CD', 'AC')
и возвращать длину этого отрезка. Ниже в коде пояснение, как это сделать.

<?php

class Point
{
    public $x;
    public $y;

    function __construct($x, $y)
    {
        $this->x = $x;
        $this->y = $y;
    }

    function distance(Point $point)
    {
        return sqrt( pow($this->x - $point->x, 2) + pow( $this->y - $point->y, 2) );
    }
}

class Trapezoid
{
    public $A;
    public $B;
    public $C;
    public $D;

    function __construct(Point $A, Point $B, Point $C, Point $D)
    {
        $this->A = $A;
        $this->B = $B;
        $this->C = $C;
        $this->D = $D;
    }

    function getLengthOfLineSegment(string $segment)
    {

    }


    function isEquilateral()
    {
        
    }

    function getSquare()
    {
        
    }

    function getPerimeter()
    {
       
    }
}

    $A = new Point (rand(5,20),rand(5,20));
    $B = new Point (rand(5,20),rand(5,20));
    $C = new Point (rand(5,20),rand(5,20));
    $D = new Point (rand(5,20),rand(5,20));

    $trapezoid = new Trapezoid($A, $B, $C, $D);

    $segment = 'AB';
    $letters = str_split($segment);

    $propertyName = $letters[0];
    echo "propertyName: $propertyName\n";
    print_r($trapezoid->$propertyName);