sanjiisan

Untitled

Apr 10th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. class BankAccount
  4. {
  5. private $number;
  6. private $balance;
  7.  
  8. public function __construct($number)
  9. {
  10. $this->number = $number;
  11. $this->balance = 0;
  12. }
  13.  
  14. public function getNumber()
  15. {
  16. return $this->number;
  17. }
  18.  
  19. public function getBalance()
  20. {
  21. return $this->balance;
  22. }
  23.  
  24. public function depositCash($amount)
  25. {
  26. if (is_numeric($amount) && $amount > 0) {
  27. $this->balance += $amount;
  28. } else {
  29. echo 'Złe dane!';
  30. return false;
  31. }
  32. }
  33.  
  34. public function withdrawCash($amount)
  35. {
  36. if (is_numeric($amount) && $amount > 0) {
  37. if ($this->balance < $amount) {
  38. return $this->balance;
  39. }
  40.  
  41. $this->balance -= $amount;
  42. } else {
  43. echo 'Złe dane!';
  44. return false;
  45. }
  46.  
  47. return $this->balance;
  48. }
  49.  
  50. public function printInfo()
  51. {
  52. return "ID konta: {$this->getNumber()}, Saldo: {$this->getBalance()}zł.<br><br>";
  53. }
  54. }
  55.  
  56. $account1 = new BankAccount(1233654654);
  57.  
  58. echo $account1->printInfo();//Puste konto
  59.  
  60. $account1->depositCash(500); //Dodajemy 500 na konto
  61. echo $account1->printInfo();//Jest 500 na koncie
  62.  
  63. $account1->withdrawCash(152); //Wyciągamy 152 na konto
  64. echo $account1->printInfo();//Jest 348 na koncie
  65.  
  66.  
  67. echo $account1->withdrawCash(500);//Ile nam pozostało
Advertisement
Add Comment
Please, Sign In to add comment