document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. class Produk {
  4.     public $judul,
  5.            $penulis,
  6.            $penerbit;
  7.  
  8.     protected $diskon = 0;
  9.  
  10.     protected $harga;
  11.  
  12.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0) {
  13.         $this->judul = $judul;
  14.         $this->penulis = $penulis;
  15.         $this->penerbit = $penerbit;
  16.         $this->harga = $harga;
  17.     }
  18.  
  19.     public function getHarga() {
  20.         return $this->harga - ($this->harga * $this->diskon / 100);
  21.     }
  22.  
  23.     public function getLabel() {
  24.         return "$this->penulis, $this->penerbit";
  25.     }
  26.  
  27.     public function getInfoProduk() {
  28.         $str = "{$this->judul} | {$this->getLabel()} (Rp. {$this->harga})";
  29.  
  30.         return $str;
  31.     }
  32.  
  33. }
  34.  
  35. class Komik extends Produk {
  36.     public $jmlHalaman;
  37.  
  38.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0) {
  39.         parent::__construct($judul, $penulis, $penerbit, $harga);
  40.  
  41.         $this->jmlHalaman = $jmlHalaman;
  42.     }
  43.  
  44.     public function getInfoProduk() {
  45.         $str = "Komik : " . parent::getInfoProduk() . " - {$this->jmlHalaman} Halaman.";
  46.         return $str;
  47.     }
  48. }
  49.  
  50. class Game extends Produk {
  51.     public $waktuMain;
  52.  
  53.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $waktuMain = 0) {
  54.         parent::__construct($judul, $penulis, $penerbit, $harga);
  55.  
  56.         $this->waktuMain = $waktuMain;
  57.     }
  58.  
  59.     public function setDiskon($diskon) {
  60.         $this->diskon = $diskon;
  61.     }
  62.  
  63.     public function getInfoProduk() {
  64.         $str = "Game : " . parent::getInfoProduk() . " ~ {$this->waktuMain} Jam.";
  65.         return $str;
  66.     }
  67. }
  68.  
  69. class CetakInfoProduk {
  70.     public function cetak( Produk $produk ) {
  71.         $str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
  72.         return $str;
  73.     }
  74. }
  75.  
  76.  
  77. $produk1 = new Komik("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000, 100);
  78. $produk2 = new Game("Uncharted", "Neil Druckmann", "Sony Computer", 250000, 50);
  79.  
  80. echo $produk1->getInfoProduk();
  81. echo "<br>";
  82. echo $produk2->getInfoProduk();
  83. echo "<hr>";
  84.  
  85. $produk2->setDiskon(50);
  86. echo $produk2->getHarga();
');