From 7514e7f60ab3a48a211978aa4603951d2c642052 Mon Sep 17 00:00:00 2001 From: CYBER-MARCUSSEN <83762741+CYBER-MARCUSSEN@users.noreply.github.com> Date: Thu, 25 Nov 2021 17:26:55 +0100 Subject: [PATCH] finished exercicies --- solution/solution.php | 198 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 solution/solution.php diff --git a/solution/solution.php b/solution/solution.php new file mode 100644 index 0000000..b908535 --- /dev/null +++ b/solution/solution.php @@ -0,0 +1,198 @@ +logout(); + } + + public function getUsername(): string + { + return $this->username; + } + + public function setUsername(string $username): void + { + $this->username = $username; + } + + public function getAge(): int + { + return $this->age; + } + + public function setAge(int $age): void + { + $this->age = $age; + } + + public function getGender(): string + { + return $this->gender; + } + + public function setGender(string $gender): void + { + $this->gender = $gender; + } + + public function getEmail(): string + { + return $this->email; + } + + public function setEmail(string $email): void + { + $this->email = $email; + } + + public function login($username, $password) + { + if (isset($username) && isset($password)) { + $this->isConnected = true; + } + } + + public function logout() + { + $this->isConnected = false; + } +} + +abstract class AdminUser extends User +{ + protected bool $hasPower; + + public function deleteCustomerUser(): void + { + // return; + } +} + +class EmployeeUser extends AdminUser +{ + public function __construct($username, $age, $gender, $email, $password, $hasPower) + { + $this->username = $username; + $this->age = $age; + $this->gender = $gender; + $this->email = $email; + $this->password = $password; + $this->hasPower = $hasPower; + } + + public function showSpecs(): string + { + return $this->username . " has " . $this->age . " years old and is a " . $this->gender; + } +} + +abstract class CustomerUser extends User +{ + protected bool $isVerified; + protected bool $isPremium; + + public function __construct($username, $age, $gender, $email, $password, $isPremium, $isVerified) + { + $this->username = $username; + $this->age = $age; + $this->gender = $gender; + $this->email = $email; + $this->password = $password; + $this->isPremium = $isPremium; + $this->isVerified = $isVerified; + } + + public function getMatchUsers(int $numberOfMatches): array + { + return []; + } + + public function setMatchUser(string $username): void + { + // + } +} + +class RegularUser extends CustomerUser +{ + const LIMIT_MATCHES = 20; + private $numberOfMatches = 0; + + public function __construct($username, $age, $gender, $email, $password, $isPremium, $isVerified) + { + // we use same constructor as father class with parent keyword and double colon + parent::__construct($username, $age, $gender, $email, $password, $isPremium, $isVerified); + } + + public function getMatchUsers(int $numberOfMatches): array + { + if ($numberOfMatches < self::LIMIT_MATCHES) { + return []; + }; + + return []; + } + + public function showSpecs(): string + { + return $this->username . " has " . $this->age . " years old and is a " . $this->gender; + } + + public function matchUser($numberOfMatches): void + { + $this->numberOfMatches = $numberOfMatches + 1; + } +} + +class PremiumUser extends CustomerUser +{ + private string $expiringDate; + + public function __construct($username, $age, $gender, $email, $password, $isPremium, $isVerified, $expiringDate) + { + // we use same constructor as father class with parent keyword and double colon + parent::__construct($username, $age, $gender, $email, $password, $isPremium, $isVerified); + // and add new arguments necessary for the new son class + $this->expiringDate = $expiringDate; + } + + public function showSpecs(): string + { + return $this->username . " has " . $this->age . " years old and is a " . $this->gender; + } + + public function getWhoHasSeenYou(): array + { + return []; + } + +} + +$employeeUser = new EmployeeUser("John", 32, "alpha male", "john@mail.org", "1234", true); +$regularUser = new RegularUser("Michael", 22, "gamma male", "michael@mail.org", "abcd", true, false); +$premiumUser = new PremiumUser("Barbara", 33, "femme fatale", "barbara@mail.org", "6666", true, true, "2024-11-12"); + +echo $employeeUser->showSpecs(); +echo '
'; +echo $regularUser->showSpecs(); +echo '
'; +echo $premiumUser->showSpecs();