All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.samples.application.bank.BankAccount Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.samples.application.bank;

/**
 * 

Abstract BankAccount class.

* * @author oaouattara * @version $Id: $Id */ public abstract class BankAccount { private AccountType type; private Money balance = Money.ZERO; private String number; private Owner owner; public boolean frozen; /** *

Constructor for BankAccount.

* * @param accountType a {@link com.greenpepper.samples.application.bank.AccountType} object. * @param number a {@link java.lang.String} object. * @param owner a {@link com.greenpepper.samples.application.bank.Owner} object. */ public BankAccount(AccountType accountType, String number, Owner owner) { this.number = number; this.type = accountType; this.owner = owner; } /** *

checkFunds.

* * @param amount a {@link com.greenpepper.samples.application.bank.Money} object. * @throws java.lang.Exception if any. */ public abstract void checkFunds(Money amount) throws Exception; /** *

withdraw.

* * @param amount a {@link com.greenpepper.samples.application.bank.Money} object. * @param withdrawType a {@link com.greenpepper.samples.application.bank.WithdrawType} object. * @return a {@link com.greenpepper.samples.application.bank.Money} object. * @throws java.lang.Exception if any. */ public Money withdraw(Money amount, WithdrawType withdrawType) throws Exception { Money limit = type.limitFor(withdrawType); if (!AccountType.isNoLimit(limit) && amount.strictlyGreaterThan(limit)) { throw new Exception("Limit overpassed"); } Money fees = type.feesFor(withdrawType); return withdraw(amount.plus(fees)); } /** *

withdraw.

* * @param amount a {@link com.greenpepper.samples.application.bank.Money} object. * @return a {@link com.greenpepper.samples.application.bank.Money} object. * @throws java.lang.Exception if any. */ public Money withdraw(Money amount) throws Exception { checkNotFrozen(); checkFunds(amount); balance = balance.minus(amount); return balance; } private void checkNotFrozen() throws Exception { if (frozen) throw new Exception("Acccount frozen!"); } /** *

Getter for the field number.

* * @return a {@link java.lang.String} object. */ public String getNumber() { return number; } /** *

deposit.

* * @param amount a {@link com.greenpepper.samples.application.bank.Money} object. * @return a {@link com.greenpepper.samples.application.bank.Money} object. */ public Money deposit(Money amount) { balance = balance.plus(amount); return balance; } /** *

Getter for the field balance.

* * @return a {@link com.greenpepper.samples.application.bank.Money} object. */ public Money getBalance() { return balance; } /** *

isFrozen.

* * @return a boolean. */ public boolean isFrozen() { return frozen; } /** *

freeze.

*/ public void freeze() { frozen = true; } /** *

Getter for the field type.

* * @return a {@link com.greenpepper.samples.application.bank.AccountType} object. */ public AccountType getType() { return type; } /** *

Getter for the field owner.

* * @return a {@link com.greenpepper.samples.application.bank.Owner} object. */ public Owner getOwner() { return owner; } /** *

getOwnerName.

* * @return a {@link java.lang.String} object. */ public String getOwnerName() { return owner.getFullName(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy