-
Notifications
You must be signed in to change notification settings - Fork 0
/
task2.php
56 lines (41 loc) · 1.54 KB
/
task2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<body>
<h1>Task 2</h1>
<?php
class Square{
private $shapeName;
private $shapeLength;
public function __construct($shapeLength){
$this->shapeName = "Square";
$this->shapeLength = $shapeLength;
}
public function setShapeLength($shapeLength){
$this->shapeLength = $shapeLength;
}
public function getShapeName(){
return $this->shapeName;
}
public function getShapeLength(){
return $this->shapeLength;
}
public function getArea(){
return $this->shapeLength * $this->shapeLength;
}
public function getPerimeter(){
return 4 * $this->shapeLength;
}
}
$SquareObj = new Square(10);
$shapeLength = $SquareObj->getShapeLength();
$shapeName = $SquareObj->getShapeName();
echo "The new shape is <strong>$shapeName</strong> and one side length is <strong>$shapeLength</strong>.<br><br>";
$SquareObj->setShapeLength(20);
$shapeLength = $SquareObj->getShapeLength();
echo "The new length is <strong>$shapeLength</strong>.<br><br>";
$area = $SquareObj->getArea();
$perimeter = $SquareObj->getPerimeter();
echo "The <strong>$shapeName's</strong> area is <strong>$area</strong> and perimeter is <strong>$perimeter</strong>"
?>
</body>
</html>