Skip to content

Instantly share code, notes, and snippets.

@recck
Created November 1, 2012 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recck/3994198 to your computer and use it in GitHub Desktop.
Save recck/3994198 to your computer and use it in GitHub Desktop.
Programming in PHP - Week 7 - Day 14 - OOP Part 2
<?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();
?>
<?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();
?>
<?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