user3320800
user3320800

Reputation: 1

php work out total area of a certain shape (maths)

I am trying to make a php product which works out area and perimeter of different shapes. There are different shapes e.g. square, rectangle, circle, triangles etc. I currently have Total Area of all shapes, count how many shapes were worked out, highest perimeter working and there is the code for it,

edit2:

abstract class Shapes
{
protected $name;
protected $colour;
function __construct($n, $c)
{
$this->name   = $n;
$this->colour = $c;
}
abstract public function area();
abstract public function perimeter();
public function printShape()
{

}

thanks

Upvotes: 0

Views: 1075

Answers (1)

Buga Dániel
Buga Dániel

Reputation: 830

In your Shapes class, create a getter (method) called getName that returns the $name property.

e.g.

abstract class Shapes
{
    protected $name;
    protected $colour;

    function __construct($n, $c)
    {
        $this->name   = $n;
        $this->colour = $c;
    }

    abstract public function area();

    abstract public function perimeter();

    public function printShape()
    {
        print "<h6>The area of the " . $this->colour . " " . $this->name . " is " . $this->area(
            ) . " and the perimeter is " . $this->perimeter() . "</h6>";
    }

    public function getName()
    {
        return $this->name;
    }

}

Upvotes: 1

Related Questions