codingan cara buat HTML

1.       Oop#6 <?php classsastra {             public $judul,                            $penulis,                            $penerbit,                            $harga,     …

codingan cara buat HTML


1.     Oop#6
<?php

classsastra {
            public $judul,
                           $penulis,
                           $penerbit,
                           $harga,
                           $jmlHalaman,
                           $waktuMain,
                           $tipe;

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0, $waktuMain = 0, $tipe) {
                        $this->judul = $judul;
                        $this->penulis = $penulis;
                        $this->penerbit =$penerbit;
                        $this->harga = $harga;
                        $this->jmlHalaman = $jmlHalaman;
                        $this->waktuMain = $waktuMain;
                        $this->tipe = $tipe;
            }

            public function hello() {
                        return "$this->penulis, $this->penerbit";
            }
            public function getInfoLengkap(){
                        // Novel :Dilan | PidiBaiq, Pastel Books (Rp. 50000) - 100 Halaman.
                        $str = "{$this->tipe} : {$this->judul} | {$this->hello()} (Rp.{$this->harga})";
                        if( $this->tipe == "Novel" ){
                                    $str .= " - {$this->jmlHalaman} Halaman.";
                        } else if( $this->tipe == "Cerpen" ) {
                                    $str .= " ~ {$this->waktuMain} Jam.";
                        }

                        return $str;
            }

}

classcetakinfosastra{
            public function cetak(sastra$sastra){
                        $str = "{$sastra->judul} | {$sastra->hello()}, {$sastra->harga})";
                        return$str;
            }
}
$sastra1 = new sastra("Dilan", "PidiBaiq", "Pastel Books", 50000, 100, 0, "Novel");
$sastra2 = new sastra("Senja", "Mr R", "John Wesley", 35000, 0, 50, "Cerpen");

echo $sastra1->getInfoLengkap();
echo "<br>";
echo $sastra2->getInfoLengkap();

2.      Oop#7
<?php

classsastra {
            public $judul,
                           $penulis,
                           $penerbit,
                           $harga,
                           $jmlHalaman,
                           $waktuMain;
                       

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0, $waktuMain = 0) {
                        $this->judul = $judul;
                        $this->penulis = $penulis;
                        $this->penerbit =$penerbit;
                        $this->harga = $harga;
                        $this->jmlHalaman = $jmlHalaman;
                        $this->waktuMain = $waktuMain;
                       
            }

            public function hello() {
                        return "$this->penulis, $this->penerbit";
            }
            public function getInfosastra(){
                       
                        $str = " {$this->judul} | {$this->hello()} (Rp.{$this->harga})";
                        return $str;
            }

}

class Novel extends sastra{
            public function getInfosastra() {
                        $str = "Novel : {$this->judul} | {$this->hello()} (Rp.{$this->harga}) - {$this->jmlHalaman} Halaman.";
                        return$str;
            }
}

classcerpen extends sastra {
            public function getInfosastra(){
                        $str = "Cerpen : {$this->judul} | {$this->hello()} (Rp.{$this->harga}) ~ {$this->waktuMain} Jam.";
                        return$str;
            }
}
classcetakinfosastra{
            public function cetak(sastra$sastra){
                        $str = "{$sastra->judul} | {$sastra->hello()}, {$sastra->harga})";
                        return$str;
            }
}
$sastra1 = new Novel("Dilan", "PidiBaiq", "Pastel Books", 50000, 100, 0);
$sastra2 = new Cerpen("Senja", "Mr R", "John Wesley", 35000, 0, 50);

echo $sastra1->getInfosastra();
echo "<br>";
echo $sastra2->getInfosastra();


3.      Oop#8
<?php

classsastra {
            public $judul,
                           $penulis,
                           $penerbit,
                           $harga;
                       
                       

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0) {
                        $this->judul = $judul;
                        $this->penulis = $penulis;
                        $this->penerbit =$penerbit;
                        $this->harga = $harga;
                       
                       
            }

            public function hello() {
                        return "$this->penulis, $this->penerbit";
            }
            public function getInfosastra(){
                       
                        $str = " {$this->judul} | {$this->hello()} (Rp.{$this->harga})";
                        return $str;
            }

}

class Novel extends sastra{
            public $jmlHalaman;

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0) {

                        parent::__construct($judul, $penulis, $penerbit, $harga);
                        $this->jmlHalaman = $jmlHalaman;

            }

            public function getInfosastra() {
                        $str = "Novel : " . parent::getInfosastra() . "  - {$this->jmlHalaman} Halaman.";
                        return$str;
            }
}

classcerpen extends sastra {
            public $waktuMain;

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $waktuMain = 0){
                        parent::__construct($judul, $penulis, $penerbit, $harga);
                        $this->waktuMain = $waktuMain;
            }
            public function getInfosastra(){
                        $str = "Cerpen : " . parent::getInfosastra() . " ~ {$this->waktuMain} Jam.";
                        return$str;
            }
}
classcetakinfosastra{
            public function cetak(sastra$sastra){
                        $str = "{$sastra->judul} | {$sastra->hello()}, {$sastra->harga})";
                        return$str;
            }
}
$sastra1 = new Novel("Dilan", "PidiBaiq", "Pastel Books", 50000, 100);
$sastra2 = new Cerpen("Senja", "Mr R", "John Wesley", 35000, 50);
echo $sastra1->getInfosastra();
echo "<br>";
echo $sastra2->getInfosastra();

4.      Oop#9
<?php

classsastra {
            public $judul,
                           $penulis,
                           $penerbit;

            protected $diskon = 0;

            private $harga;
                       
                       

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0) {
                        $this->judul = $judul;
                        $this->penulis = $penulis;
                        $this->penerbit =$penerbit;
                        $this->harga = $harga;
                       
                       
            }
           
            public function getharga() {
                        return $this->harga - ($this->harga * $this->diskon / 100);
            }

            public function hello() {
                        return "$this->penulis, $this->penerbit";
            }
            public function getInfosastra(){
                       
                        $str = " {$this->judul} | {$this->hello()} (Rp.{$this->harga})";
                        return $str;
            }

}

class Novel extends sastra{
            public $jmlHalaman;

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jmlHalaman = 0) {

                        parent::__construct($judul, $penulis, $penerbit, $harga);
                        $this->jmlHalaman = $jmlHalaman;

            }

            public function getInfosastra() {
                        $str = "Novel : " . parent::getInfosastra() . "  - {$this->jmlHalaman} Halaman.";
                        return$str;
            }
}

classcerpen extends sastra {
            public $waktuMain;

            public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $waktuMain = 0){
                        parent::__construct($judul, $penulis, $penerbit, $harga);
                        $this->waktuMain = $waktuMain;
            }
            public function setdiskon( $diskon ) {
                        $this->diskon = $diskon;
            }

           
            public function getInfosastra(){
                        $str = "Cerpen : " . parent::getInfosastra() . " ~ {$this->waktuMain} Jam.";
                        return$str;
            }
}
classcetakinfosastra{
            public function cetak(sastra$sastra){
                        $str = "{$sastra->judul} | {$sastra->hello()}, {$sastra->harga})";
                        return$str;
            }
}
$sastra1 = new Novel("Dilan", "PidiBaiq", "Pastel Books", 50000, 100);
$sastra2 = new Cerpen("Senja", "Mr R", "John Wesley", 35000, 50);
echo $sastra1->getInfosastra();
echo "<br>";
echo $sastra2->getInfosastra();
echo "<hr>";
$sastra2->setdiskon(20);
echo $sastra2->getharga();





Terbaru Lebih lama

Related Posts

There is no other posts in this category.

Posting Komentar

Subscribe Our Newsletter