Skip to content

Instantly share code, notes, and snippets.

@taufikherjanto
Created October 3, 2016 09:28
Show Gist options
  • Save taufikherjanto/d6b957875f76e0b331ced7e51490882e to your computer and use it in GitHub Desktop.
Save taufikherjanto/d6b957875f76e0b331ced7e51490882e to your computer and use it in GitHub Desktop.
<?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