-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject-type.php
More file actions
54 lines (33 loc) · 868 Bytes
/
object-type.php
File metadata and controls
54 lines (33 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class Produk {
public $judul,
$penulis,
$penerbit,
$harga;
public function __construct($judul, $penulis, $penerbit, $harga)
{
$this->judul = $judul;
$this->penulis = $penulis;
$this->penerbit = $penerbit;
$this->harga = $harga;
}
public function getLabel()
{
return "$this->penulis, $this->penerbit";
}
}
class CetakInfoProduk{
public function cetak( Produk $produk ){
$str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
return $str;
}
}
$produk1 = new Produk("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000);
$produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer", 100000);
echo "Komik : " . $produk1->getLabel();
echo "<br>";
echo "Game : " . $produk2->getLabel();
echo "<br>";
$infoProduk1 = new CetakInfoProduk();
echo $infoProduk1->cetak($produk1);
?>