function areaVerifier(Rectangle $r) { $r->setWidth(5); $r->setHeight(4); if ($r->area() != 20) { return false; } return true; }
<?php require_once "rectangle.php"; require_once "square.php"; $rect1 = new Rectangle(2, 7); echo $rect1->area(); echo "\n"; echo $rect1->perimeter(); echo "\n"; $rect2 = new Rectangle(3, 4); echo $rect2->area(); echo "\n"; echo $rect2->perimeter(); echo "\n"; $square1 = new Square(2); echo $square1->area(); echo "\n"; echo $square1->perimeter(); echo "\n"; $square1 = new Square(3); echo $square1->area(); echo "\n"; echo $square1->perimeter(); echo "\n"; ?> ?>
<?php require_once 'square.php'; $rectangle = new Rectangle(20, 40); echo 'The area of this rectangle is ' . $rectangle->area() . PHP_EOL; $square = new Square(20); echo 'The perimeter of this square is ' . $square->perimeter() . PHP_EOL;
$this->setWidth($width); } protected function setHeight($height) { $this->height = $height; } protected function setWidth($width) { $this->width = $width; } protected function getHeight() { return $this->height; } protected function getWidth() { return $this->width; } public function area() { return $this->getHeight() * $this->getWidth(); } public function perimeter() { return $this->getHeight() * 2 + $this->getWidth() * 2; } } $rectangle = new Rectangle(10, 10); echo $rectangle->area(); echo $rectangle->getHeight(); echo $rectangle->getWidth();
<!-- shapes_test.php --> <!-- 9.2.1 --> <?php require_once 'square.php'; // use this to run rectangle $shape = new Rectangle(11, 39); echo 'Area of Rectangle = ' . $shape->area() . PHP_EOL; $square = new Square(2, 2); echo 'Perimiter of square = ' . $square->Perimeter(); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>shapes_test.php</title> </head> <body> <h1> shapes_test.php | 9.2.1</h1> <script> console.log("INCLUDED: shapes_test.php") </script> </body> </html>
<?php require_once 'rectangle.php'; require_once 'square.php'; // Test your new class by creating an instance of Rectangle with various heights and widths. $rekt_one = new Rectangle(7, 14); $rekt_two = new Rectangle('5', '10'); $rekt_three = new Rectangle(33.33, 66.66); $square_one = new Square(4); // Calling the area method should correctly display the product of height and width. var_dump($rekt_one->area()); var_dump($rekt_one->perimeter()); // var_dump($rekt_two->area()); // var_dump($rekt_three->area()); var_dump($square_one->perimeter()); var_dump($square_one->area());
<?php require_once "rectangle.php"; require_once "square.php"; $rectangle = new Rectangle(4, 8); $square = new Square(41); echo $rectangle->area() . PHP_EOL; echo $rectangle->perimeter() . PHP_EOL; echo $square->area() . PHP_EOL; echo $square->perimeter() . PHP_EOL;
<?php require_once "rectangle.php"; require_once "square.php"; $squr = new Square(10, 30); $area = $squr->equalarea() . " sq."; echo $area . PHP_EOL; $perimeter = $squr->perimeter() . " long."; echo $perimeter . PHP_EOL; $rect = new Rectangle(10, 30); $area = $rect->area() . " sq."; echo $area . PHP_EOL; $perimeter = $rect->perimeter() . " long."; echo $perimeter . PHP_EOL;
<?php require_once 'rectangle.php'; require_once 'square.php'; $rectangle = new Rectangle(10, 10); echo $rectangle->area() . PHP_EOL; echo "The area of a rectangle with height of {$rectangle->getHeight()} and width of {$rectangle->getWidth()} is {$rectangle->area()} " . PHP_EOL; echo "The perimeter of a rectangle with height of {$rectangle->getHeight} and width of {$rectangle->getWidth()} is {$rectangle->perimeter()} " . PHP_EOL; // $square = new Square(5); // echo "The area of a square with height of {$square->height} is {$square->area()} " . PHP_EOL; // echo "The perimeter of a square with height of {$square->height} is {$square->perimeter()} " . PHP_EOL;