Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions abstract-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// Parent class
abstract class Feline {
public $name;
public $whiskerType;

public function __construct(string $name, string $whiskerType) {
$this->name = $name;
$this->whiskerType = $whiskerType;
}
abstract public function whoAreYou() : string;
}

// Child classes
class Leon extends Feline {
public function whoAreYou() : string {
return "I'm a king! I'm a $this->name!";
}
}

class Pantera extends Feline {
public function whoAreYou() : string {
return "I'm a very fast ! I'm a $this->name!";
}
}

class Tiger extends Feline {
public function whoAreYou() : string {
return "I'm a cute! I'm a $this->name!";
}
}

// Create objects from the child classes
/*$leon = new Leon("Leon", "long");
echo $leon->whoAreYou();
echo "<br>";

$pantera = new Pantera("Pantera", "median");
echo $pantera->whoAreYou();
echo "<br>";

$tiger = new Tiger("Tiger", "very long");
echo $tiger->whoAreYou();*/
?>
66 changes: 66 additions & 0 deletions animal-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

class animals {
public $name;
public $type;
public $age;
public $vertebrates;
public $warmBlooded;


function __construct(string $name, string $type, int $age, bool $vertebrates, bool $warmBlooded){
$this->name=$name;
$this->type=$type;
$this->age=$age;
$this->vertebrates=$vertebrates;
$this->warmBlooded=$warmBlooded;
}


public function showAnimal(string $name, string $type, $age, bool $vertebrates, bool $warmBlooded){
$subType = true;
$blood = true;
if ($vertebrates === true){
$subType = "vertebrates";
}else{
$subType = "invertebrates";
}

if( $warmBlooded === true){
$blood = "warm-blooded";
}else{
$blood = "cold-blooded";
}

echo "
<h1>$name</h1>
<b>Type:</b> $type,<br>
<b>Subtype:</b> $subType,<br>
<b>Age:</b> $this->age,<br>
<b>Group:</b> $blood,<br>";

}

public function canBreath(string $name, string $breath){
echo "<br><p><b>How Do $name Breathe?</b></p> $breath";
}

public function canMove(string $name, string $movement){
echo "<br><p><b>How Do $name move?</b></p> $movement";
}

public function makeSound(string $name, string $sound){
echo "<br><p><b>Does $name make any sound?</b></p> $sound";
}




public function __destruct(){
print "Destruct " . __CLASS__ . "\n";
}
}

?>


78 changes: 78 additions & 0 deletions animal-object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>

<div class="container-md">

<?php
require_once ("animal-class.php");
require_once ("animal-with-interitance.php");
require_once ("interface.php");
require_once ("abstract-class.php");


$tiger = new animals("Tiger", "Mammal", 10, true, true);
$tiger->showAnimal("Tiger", "Mammal", 10, true, true);
$tiger->canBreath("Tiger", "The respiratory system consists of the lungs. Just like humans and all mammals, Siberian tigers breathe through their nose and mouth into their lungs.");
$tiger->canMove("Tiger", "They can run, jump, climb. The hind legs of the tiger are longer than their front legs. This characteristic enables them to leap forward distances up to 10 meters.");
$tiger->makeSound("Tiger", "They growl, roar, chuff and moan.");

$crocodile = new animals("Crocodile", "Reptiles", 25, true, false);
$crocodile->showAnimal("Crocodile", "Reptiles", 25, true, false);
$crocodile->canBreath("Crocodile", "When basking on land with the mouth open, crocodilians breathe mostly through their mouth (the throat/palatal valve is open). When in water, the mouth is usually closed and they breathe mostly through their nostrils.");
$crocodile->canMove("Crocodile", "The right front and left rear legs are lifted and moved forward while the front right and rear left legs, already on the ground, push backwards, propelling the crocodile's body forward.");
$crocodile->makeSound("Crocodile", "Adults crocodiles hiss and bellow at each other. Babies chirp when they hatch.");

$cat = new cats ("Cat", "Mammal", 2, true, true, "Maine Coon");
$cat->setAge($cat->getAge()*7);
$age = $cat->age;
$cat->showAnimal("Cat", "Mammal", $age, true, true, "Maine Coon");
$cat->showBreed("Maine Coon");
$cat->canBreath("Cat", "A healthy respiratory (breathing) rate for a cat is usually between 20 and 30 breaths per minute.");
$cat->canMove("Cat", "Cats are digitigrade; that is, they walk on their toes.");
#$cat->makeSound("Cat", "Already in ancient Egypt the quintessential sound of a cat was “meow”, which meant “cat”. This sound can last between a fraction of a second and various seconds and cats produce it by opening their mouth and then gradually closing it again.<br><br>");
$cat->makePurr("Cats purr when they're content");
/*$cat->getMeow();
$cat->setMeow("Meoooooow");*/
$cat->makeSound("cat", "meoww");


echo "<br><hr>INTERFACE";
//Interface
$dog = new Dog();
$mouse = new Mouse();
$animals = array($dog, $mouse);

foreach($animals as $animal) {
$animal->eat();
$animal->move();
}


// Create objects from the child classes
echo "<br><p><b>ABSTRACT CLASS</p></b>";
$leon = new Leon("Leon", "long");
echo $leon->whoAreYou();
echo "<br>";

$pantera = new Pantera("Pantera", "median");
echo $pantera->whoAreYou();
echo "<br>";

$tiger = new Tiger("Tiger", "very long");
echo $tiger->whoAreYou() . "<br><br>";

?>

</div>
</body>
</html>
41 changes: 41 additions & 0 deletions animal-with-interitance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
require_once("animal-class.php");
require_once("animal-object.php");

class cats extends animals{
protected $breed;

function __construct(string $name, string $type, int $age, bool $vertebrates, bool $warmBlooded, string $breed){
parent::__construct($name, $type, $age, $vertebrates, $warmBlooded);
$this->breed=$breed;
}

public function showBreed(string $breed){
echo "<b>Breed:</b> $breed <br>";
}

public function makePurr(string $purr){
echo "<br><br><b>Purr:</b> $purr <br>
<audio controls><source src='sound/cat.mp3' type='audio/mpeg'>
</audio>";
}

// override //

public function getAge(){
return $this->age;
}

public function setAge($ageNew){
$this->age = $ageNew;
return $this;
}

public function makeSound(string $name, string $sound){
echo "<p><b>How speaks a $name?</b></p> $sound";
return $sound;
}

}

?>
Loading