Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- A bank account has a balance that can be changed by
- deposits and withdrawals.
- */
- public class CheckingAccount
- {
- private final double CHECK_CHARGE = 0.15;
- private double myBalance;
- /**
- Constructs a bank account with a zero balance
- */
- public CheckingAccount()
- {
- myBalance = 0;
- }
- /**
- Constructs a bank account with a given balance
- @param initialBalance the initial balance
- */
- public CheckingAccount(double initialBalance)
- {
- if (initialBalance >= 0)
- myBalance = initialBalance;
- else
- throw new IllegalArgumentException("Error CheckingAccount: negative initial balance");
- }
- /**
- Deposits money into the bank account.
- @param amount the amount to deposit
- */
- public void deposit(double amount)
- {
- if (amount >= 0)
- myBalance = myBalance + amount;
- else
- throw new IllegalArgumentException("Error deposit: negative amount");
- }
- /**
- Withdraws money from the bank account.
- @param amount the amount to withdraw
- */
- public void withdraw(double amount)
- {
- if (amount >= 0 && amount <= (myBalance - CHECK_CHARGE))
- myBalance = myBalance - amount - CHECK_CHARGE;
- else
- throw new IllegalArgumentException("Error withdraw: illegal amount");
- }
- /**
- Gets the current balance of the bank account.
- @return the current balance
- */
- public double getBalance()
- {
- return myBalance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment