-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask6.php
71 lines (55 loc) · 1.87 KB
/
task6.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Author : Fabio Pinto
* Description as per requirements :
* Create a class named Animals, that when called, will access the properties of the class and produce the
* output here below. The class must have a constructor and get and set methods.
**/
class Animals {
//Classes properties
private $cat;
private $dog;
private $bird;
//Constructor method when new objects of this class are instantiated. Parameters are optional.
public function __construct($cat = NULL, $dog = NULL, $bird = NULL) {
$this->cat = $cat;
$this->dog = $dog;
$this->bird = $bird;
}
//Getter methods of the Aanimalks properties
public function getCat() {
return $this->cat;
}
public function getDog() {
return $this->dog;
}
public function getBird() {
return $this->bird;
}
//Setter methods for the Animals properties
public function setCat($cat) {
$this->cat = $cat;
}
public function setDog($dog) {
$this->dog = $dog;
}
public function setBird($bird) {
$this->bird = $bird;
}
}
//New object from the Animals class.
$pettingZoo = new Animals("Tabby Cat", "Jack Russel Terrior", "Budgie");
//Different new object from Animals class demonstrating not setting properties with the contructor but rather with the setter methods of the class.
$animalFarm = new Animals();
$animalFarm->setCat('British Short Hair');
$animalFarm->setDog('Maltese Poodle');
$animalFarm->setBird('Bald Eagle');
//Echoing the pettingZoo objects properties
echo 'The animals are a '.$pettingZoo->getDog().' ,a '.$pettingZoo->getCat().' and a '.$pettingZoo->getBird().'.';
echo '</br></br>';
//Echoing the animalFarm objects properties
echo 'The animals are a '.$animalFarm->getDog().' ,a '.$animalFarm->getCat().' and a '.$animalFarm->getBird().'.';
?>
</br><a href="index.html">Back...<a>
</br><iframe src="task6.txt" height="400" width="1200">
<p>Your browser does not support iframes.</p></iframe>