Advertisement
cecepsuwanda

oop_warnet

Oct 1st, 2022
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?PHP
  2. //Komplek warnet
  3. //ada gamenya
  4. class Warnet{
  5.    
  6.     //property
  7.     public $nama = "Judul";
  8.     public $alamat;
  9.     public $daftarGame;
  10.     public $kapasitas = "20";
  11.  
  12.     //method
  13.    
  14.     public function __construct($nama, $alamat, $daftarGame, $kapasitas){
  15.         $this->nama = $nama;
  16.         $this->alamat = $alamat;
  17.         $this->daftarGame = $daftarGame;
  18.         $this->kapasitas = $kapasitas;
  19.     }
  20.  
  21.     public function info(){
  22.    
  23.         $jml_game = count($this->daftarGame);
  24.         $game='';
  25.         for($i=0; $i < ($jml_game-1); $i++){
  26.             $game= $game.$this->daftarGame[$i].",";
  27.         }
  28.         $game=$game.$this->daftarGame[$jml_game-1];        
  29.         return "$this->nama,$this->kapasitas ! $game ! $this->alamat";
  30.     }
  31.        
  32. }
  33.  
  34. //property
  35. $warnet2 = new Warnet("Tadika", "Kalimantan", ["Apex", "LS", "PB"], 32);
  36. $warnet3 = new Warnet("Kulkulu", "Mandrago", ["LoL", "Dota", "Mountain Bike"], 21);
  37.  
  38. echo $warnet2->info();
  39. echo "<br>";
  40. echo $warnet3->info();
  41. echo "<br>";
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement