document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. class Produk {
  4.     private $judul,
  5.            $penulis,
  6.            $penerbit,
  7.            $harga,
  8.            $diskon = 0;
  9.  
  10.  
  11.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0) {
  12.         $this->judul = $judul;
  13.         $this->penulis = $penulis;
  14.         $this->penerbit = $penerbit;
  15.         $this->harga = $harga;
  16.     }
  17.  
  18.     public function setJudul( $judul ) {
  19.         $this->judul = $judul;
  20.     }
  21.  
  22.     public function getJudul() {
  23.         return $this->judul;
  24.     }
  25.  
  26.     public function setPenulis ( $penulis )  {
  27.         $this->penulis = $penulis;
  28.     }
  29.  
  30.     public function getPenulis() {
  31.         return $this->penulis;
  32.     }
  33.  
  34.     public function setPenerbit( $penerbit ) {
  35.         $this->penerbit = $penerbit;
  36.     }
  37.  
  38.     public function getPenerbit() {
  39.         return $this->penerbit;
  40.     }
  41.  
  42.     public function setDiskon( $diskon ) {
  43.         $this->diskon = $diskon;
  44.     }
  45.  
  46.     public function getDiskon() {
  47.         return $this->diskon;
  48.     }
  49.  
  50.     public function setHarga( $harga ) {
  51.         $this->harga = $harga;
  52.     }
  53.  
  54.     public function getHarga() {
  55.         return $this->harga - ($this->harga * $this->diskon / 100);
  56.     }
  57.  
  58.     public function getLabel() {
  59.         return "$this->penulis, $this->penerbit";
  60.     }
  61.  
  62.     public function getInfoProduk() {
  63.         $str = "{$this->judul} | {$this->getLabel()} (Rp. {$this->harga})";
  64.  
  65.         return $str;
  66.     }
  67.  
  68. }
  69.  
  70. class Komik extends Produk {
  71.     public $jmlHalaman;
  72.  
  73.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0) {
  74.         parent::__construct($judul, $penulis, $penerbit, $harga);
  75.  
  76.         $this->jmlHalaman = $jmlHalaman;
  77.     }
  78.  
  79.     public function getInfoProduk() {
  80.         $str = "Komik : " . parent::getInfoProduk() . " - {$this->jmlHalaman} Halaman.";
  81.         return $str;
  82.     }
  83. }
  84.  
  85. class Game extends Produk {
  86.     public $waktuMain;
  87.  
  88.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $waktuMain = 0) {
  89.         parent::__construct($judul, $penulis, $penerbit, $harga);
  90.  
  91.         $this->waktuMain = $waktuMain;
  92.     }
  93.  
  94.     public function getInfoProduk() {
  95.         $str = "Game : " . parent::getInfoProduk() . " ~ {$this->waktuMain} Jam.";
  96.         return $str;
  97.     }
  98. }
  99.  
  100. class CetakInfoProduk {
  101.     public function cetak( Produk $produk ) {
  102.         $str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
  103.         return $str;
  104.     }
  105. }
  106.  
  107.  
  108. $produk1 = new Komik("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000, 100);
  109. $produk2 = new Game("Uncharted", "Neil Druckmann", "Sony Computer", 250000, 50);
  110.  
  111. echo $produk1->getInfoProduk();
  112. echo "<br>";
  113. echo $produk2->getInfoProduk();
  114. echo "<hr>";
  115.  
  116. $produk2->setDiskon(50);
  117. echo $produk2->getHarga();
  118. echo "<hr>";
  119.  
  120. $produk1->setPenulis("Yosho");
  121. echo $produk1->getPenulis();
');