Advertisement
yoshoo

Untitled

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