intellij version of CashMachineBlueJ

Account.java 948B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @author ZipCodeWilmington
  3. */
  4. public abstract class Account {
  5. private AccountData accountData;
  6. public Account(AccountData accountData) {
  7. this.accountData = accountData;
  8. }
  9. public AccountData getAccountData() {
  10. return accountData;
  11. }
  12. public void deposit(int amount) {
  13. updateBalance(getBalance() + amount);
  14. }
  15. public boolean withdraw(int amount) {
  16. if (canWithdraw(amount)) {
  17. updateBalance(getBalance() - amount);
  18. return true;
  19. } else {
  20. return false;
  21. }
  22. }
  23. protected boolean canWithdraw(int amount) {
  24. return getBalance() >= amount;
  25. }
  26. public int getBalance() {
  27. return accountData.getBalance();
  28. }
  29. private void updateBalance(int newBalance) {
  30. accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
  31. newBalance);
  32. }
  33. }