Created
October 3, 2016 09:28
-
-
Save taufikherjanto/d6b957875f76e0b331ced7e51490882e to your computer and use it in GitHub Desktop.
This file contains 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 Segitiga { | |
public function calculate(); | |
} | |
class Keliling implements Segitiga | |
{ | |
private $a; | |
private $b; | |
private $c; | |
public function __construct($a, $b, $c) { | |
$this->a = $a; | |
$this->b = $b; | |
$this->c = $c; | |
} | |
public function calculate() { | |
return $this->a + $this->b + $this->c; | |
} | |
} | |
class Luas implements Segitiga | |
{ | |
private $a; | |
private $b; | |
public function __construct($a, $b) { | |
$this->a = $a; | |
$this->b = $b; | |
} | |
public function calculate() { | |
return ($this->a * $this->b) / 2; | |
} | |
} | |
$keliling = new Keliling(10, 20, 30); | |
$luas = new Luas(10, 30); | |
echo 'Keliling: '.$keliling->calculate(); | |
echo PHP_EOL; | |
echo 'Luas: '.$luas->calculate(); | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment