Created
November 1, 2012 15:09
-
-
Save recck/3994198 to your computer and use it in GitHub Desktop.
Programming in PHP - Week 7 - Day 14 - OOP Part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'Vehicle.php'; | |
class Car implements Vehicle { | |
private $seats; | |
private $type; | |
public function __construct($seats, $type){ | |
$this->seats = $seats; | |
$this->type = $type; | |
} | |
public function getRowsOfSeats(){ | |
$rows = 1; | |
$remainingSeats = $this->seats - 2; | |
if($remainingSeats > 0){ | |
$rows += ceil($remainingSeats/3); | |
} | |
return $rows; | |
} | |
public function getDoors(){ | |
return ($this->type == 'sedan') ? 4 : 2; | |
} | |
public function getType(){ | |
return 'Car'; | |
} | |
} | |
$car = new Car(5, 'coupe'); | |
echo $car->getDoors(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'Vehicle.php'; | |
class Plane implements Vehicle { | |
private $seats; | |
public function __construct($seats){ | |
$this->seats = $seats; | |
} | |
public function getRowsOfSeats(){ | |
return ceil($this->seats/4); | |
} | |
public function getType(){ | |
return 'Plane'; | |
} | |
public function getDoors(){ | |
return 1; | |
} | |
} | |
$plane = new Plane(63); | |
echo $plane->getDoors(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Vehicle { | |
public function getType(); | |
public function getRowsOfSeats(); | |
public function getDoors(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment