Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class BankAccount
- {
- private $number;
- private $balance;
- public function __construct($number)
- {
- $this->number = $number;
- $this->balance = 0;
- }
- public function getNumber()
- {
- return $this->number;
- }
- public function getBalance()
- {
- return $this->balance;
- }
- public function depositCash($amount)
- {
- if (is_numeric($amount) && $amount > 0) {
- $this->balance += $amount;
- } else {
- echo 'Złe dane!';
- return false;
- }
- }
- public function withdrawCash($amount)
- {
- if (is_numeric($amount) && $amount > 0) {
- if ($this->balance < $amount) {
- return $this->balance;
- }
- $this->balance -= $amount;
- } else {
- echo 'Złe dane!';
- return false;
- }
- return $this->balance;
- }
- public function printInfo()
- {
- return "ID konta: {$this->getNumber()}, Saldo: {$this->getBalance()}zł.<br><br>";
- }
- }
- $account1 = new BankAccount(1233654654);
- echo $account1->printInfo();//Puste konto
- $account1->depositCash(500); //Dodajemy 500 na konto
- echo $account1->printInfo();//Jest 500 na koncie
- $account1->withdrawCash(152); //Wyciągamy 152 na konto
- echo $account1->printInfo();//Jest 348 na koncie
- echo $account1->withdrawCash(500);//Ile nam pozostało
Advertisement
Add Comment
Please, Sign In to add comment