Advertisement
yoshoo

Untitled

Aug 25th, 2019
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. class Produk {
  4.     public $judul,
  5.            $penulis,
  6.            $penerbit,
  7.            $harga,
  8.            $jmlHalaman,
  9.            $waktuMain;
  10.  
  11.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = "0", $jmlHalaman, $waktuMain) {
  12.         $this->judul = $judul;
  13.         $this->penulis = $penulis;
  14.         $this->penerbit = $penerbit;
  15.         $this->harga = $harga;
  16.         $this->jmlHalaman = $jmlHalaman;
  17.         $this->waktuMain = $waktuMain;
  18.     }
  19.  
  20.     public function getLabel() {
  21.         return "$this->penulis, $this->penerbit";
  22.     }
  23.  
  24.     public function getInfoProduk() {
  25.         $str = "{$this->judul} | {$this->getLabel()} (Rp. {$this->harga})";
  26.  
  27.         return $str;
  28.     }
  29.  
  30. }
  31.  
  32. class Komik extends Produk {
  33.     public function getInfoProduk() {
  34.         $str = "Komik : {$this->judul} | {$this->getLabel()} (Rp. {$this->harga}) - {$this->jmlHalaman} Halaman.";
  35.         return $str;
  36.     }
  37. }
  38.  
  39. class Game extends Produk {
  40.     public function getInfoProduk() {
  41.         $str = "Game : {$this->judul} | {$this->getLabel()} (Rp. {$this->harga}) ~ {$this->waktuMain} Jam.";
  42.         return $str;
  43.     }
  44. }
  45.  
  46. class CetakInfoProduk {
  47.     public function cetak( Produk $produk ) {
  48.         $str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
  49.         return $str;
  50.     }
  51. }
  52.  
  53.  
  54. $produk1 = new Komik("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000, 100, 0);
  55. $produk2 = new Game("Uncharted", "Neil Druckmann", "Sony Computer", 250000, 0, 50);
  56.  
  57. echo $produk1->getInfoProduk();
  58. echo "<br>";
  59. echo $produk2->getInfoProduk();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement