Advertisement
yoshoo

Untitled

Aug 25th, 2019
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. class Produk {
  4.     public $judul,
  5.            $penulis,
  6.            $penerbit,
  7.            $harga;
  8.  
  9.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = "0") {
  10.         $this->judul = $judul;
  11.         $this->penulis = $penulis;
  12.         $this->penerbit = $penerbit;
  13.         $this->harga = $harga;
  14.     }
  15.  
  16.     public function getLabel() {
  17.         return "$this->penulis, $this->penerbit";
  18.     }
  19. }
  20.  
  21. class CetakInfoProduk {
  22.     public function cetak( Produk $produk ) {
  23.         $str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
  24.         return $str;
  25.     }
  26. }
  27.  
  28.  
  29. $produk1 = new Produk("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000);
  30. $produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer", 250000);
  31.  
  32. echo "Komik : " . $produk1->getLabel();
  33. echo "<br>";
  34. echo "Game : " . $produk2->getLabel();
  35. echo "<br>";
  36.  
  37. $infoProduk1 = new CetakInfoProduk();
  38. echo $infoProduk1->cetak($produk1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement