SHARE
TWEET

Untitled

a guest Mar 20th, 2017 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //poniżej napisz kod definiujący klasę
  3.  
  4. class Member {
  5.     private $userName;
  6.     private $password;
  7.     private $accesLevel = 0;
  8.    
  9.     function __construct($userName, $password) {
  10.         if (is_string($userName) && is_string($password)) {
  11.             if (strlen($userName) >= 5) {
  12.                 $this->setUsername($userName);
  13.             } else {
  14.                 $this->userName = $this->generateRandomString();
  15.             }
  16.             if (strlen($password) >= 5) {
  17.                 $this->setPassword($password);
  18.             } else {
  19.                 $this->password = $this->generateRandomString();
  20.             }
  21.         }
  22.         echo "Stworzono członka " . $this->userName. " o haśle " . $this->password . "\n<br>";
  23.     }
  24.  
  25.     function __destruct() {
  26.         echo "<br>\nObiekt użytkownika " . $this->getuserName() . " został zniszczony";
  27.     }
  28.     private function getuserName() {
  29.         return $this->userName;
  30.     }
  31.  
  32.     private function setuserName($userName) {
  33.     $this->userName = $userName;
  34.     }
  35.  
  36.     private function setPassword($password) {
  37.     $this->password = $password;
  38.     }
  39.    
  40.     private function getpassword() {
  41.         return $this->password;
  42.     }
  43.    
  44.     public function info(){
  45.         echo "Użytkownik " . $this->userName . " o haśle " . $this->getpassword() . "<br>\n";
  46.     }
  47.    
  48.     private function generateRandomString($length = 5) {
  49.         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  50.         $charactersLength = strlen($characters);
  51.         $randomString = '';
  52.         for ($i = 0; $i < $length; $i++) {
  53.             $randomString .= $characters[rand(0, $charactersLength - 1)];
  54.         }
  55.         return $randomString;
  56.     }
  57. }
  58.  
  59. $obj= new Member('Stefan', "Armata");
  60. $obj2= new Member('Michał', "Arm");
  61. $obj->info();
  62. $obj3= new Member('Stef', "Wiśnia");
  63. $obj4= new Member('Małgosia', "Kałach");
  64. $obj4->info();
  65. $obj5= new Member('Heller', "Tomasz");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top