Advertisement
sanjiisan

Untitled

Apr 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. class BankAccount
  4. {
  5. private static $nextAccNumber = 1;
  6.  
  7. private $number;
  8. private $balance;
  9.  
  10. public function __construct()
  11. {
  12. $this->number = self::$nextAccNumber;
  13. $this->balance = 0;
  14.  
  15. self::$nextAccNumber++;
  16. }
  17.  
  18. function getNumber()
  19. {
  20. return $this->number;
  21. }
  22.  
  23. function getBalance()
  24. {
  25. return $this->balance;
  26. }
  27.  
  28. public function depositCash($amount)
  29. {
  30. if (!is_numeric($amount) || $amount <= 0) {
  31. return false;
  32. }
  33. $this->balance += $amount;
  34. }
  35.  
  36. public function withdrawCash($amount)
  37. {
  38. if (!is_numeric($amount) || $amount < 0) {
  39. return false;
  40. }
  41.  
  42. $rest = $this->balance - $amount;
  43.  
  44. if ($rest < 0) {
  45. return $amount;
  46. }
  47.  
  48. $this->balance = $rest;
  49. return $amount;
  50. }
  51.  
  52. public function printInfo()
  53. {
  54. echo "ID konta: " . $this->number . ", saldo: " . $this->balance . "<br>";
  55. }
  56.  
  57. }
  58.  
  59. $user1 = new BankAccount();
  60. $user2 = new BankAccount();
  61. $user3 = new BankAccount();
  62. $user4 = new BankAccount();
  63. $user5 = new BankAccount();
  64.  
  65.  
  66. var_dump($user3);
  67. var_dump($user5);
  68. var_dump($user1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement