Rofihimam

Untitled

Feb 12th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.     include 'KelompokMakan.php';
  3.     class Manusia extends KelompokMakan
  4.     {
  5.         private $nama;
  6.         private $jenis_kelamin;
  7.         private $tanggal_lahir;
  8.  
  9.         function setNama($nama)
  10.         {
  11.             $this->nama = $nama;
  12.         }
  13.  
  14.         function getNama()
  15.         {
  16.             return $this->nama;
  17.         }
  18.  
  19.         function setJenisKelamin($jenis_kelamin)
  20.         {
  21.             $this->jenis_kelamin = $jenis_kelamin;
  22.         }
  23.  
  24.         function getJenisKelamin()
  25.         {
  26.             return $this->jenis_kelamin;
  27.         }
  28.  
  29.         function setTanggalLahir($tanggal_lahir)
  30.         {
  31.             $this->tanggal_lahir = $tanggal_lahir;
  32.         }
  33.  
  34.         function getTanggalLahir()
  35.         {
  36.             return $this->tanggal_lahir;
  37.         }
  38.  
  39.         public function bersuara()
  40.         {
  41.             return $this->nama;
  42.         }
  43.  
  44.         public function usia()
  45.         {
  46.             $date = date_create_from_format("d/m/Y", $this->tanggal_lahir);
  47.             $tahunLahir = $date->format('Y');
  48.             $tahunSekarang = date('Y');
  49.             $usia = $tahunSekarang - $tahunLahir;
  50.             return $usia;
  51.         }
  52.     }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment