No Description

BankAccount.php 630B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class BankAccount
  3. {
  4. protected $balance = 0;
  5. public function getBalance()
  6. {
  7. return $this->balance;
  8. }
  9. protected function setBalance($balance)
  10. {
  11. if ($balance >= 0) {
  12. $this->balance = $balance;
  13. } else {
  14. throw new RuntimeException;
  15. }
  16. }
  17. public function depositMoney($balance)
  18. {
  19. $this->setBalance($this->getBalance() + $balance);
  20. return $this->getBalance();
  21. }
  22. public function withdrawMoney($balance)
  23. {
  24. $this->setBalance($this->getBalance() - $balance);
  25. return $this->getBalance();
  26. }
  27. }