Question
You must write tests for the following: It should have 3 exception classes; AccountIDFormatException,DepositLimitException,NegativeBalanceException You must write tests for the following (which may include Custom
You must write tests for the following:
It should have 3 exception classes; AccountIDFormatException,DepositLimitException,NegativeBalanceException
You must write tests for the following (which may include Custom Exceptions):
- BankAccount1 Class
-
Tests are written such that any deposit that is made greater than 10000 is not accepted.
-
Tests are written such that balance in the BankAccount1 does not go below 0.
-
Care should be taken for above tests at the time of Initial Deposit and at the time of Withdrawal and future Deposits.
-
Make corresponding changes in methods of BankAccount1 class to invoke exceptions.
-
CODE: BankAccount1.java
public class BankAccount1 { private String accountID; private double balance;
/** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount1(String accountID) { balance = 0; this.accountID = accountID; }
/** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount1(double initialBalance, String accountID) {
this.accountID = accountID; balance = initialBalance; } /** * Returns the Account ID * @return the accountID */ public String getAccountID() { return accountID; } /** * Sets the Account ID * @param accountID */ public void setAccountID(String accountID) { this.accountID = accountID; }
/** Deposits money into the bank account. @param amount the amount to deposit */ public void deposit(double amount) {
balance += amount; }
/** Withdraws money from the bank account. @param amount the amount to withdraw @return true if allowed to withdraw */ public boolean withdraw(double amount) { boolean isAllowed = balance >= amount; if (isAllowed) balance -= amount; return isAllowed; }
/** Gets the current balance of the bank account. @return the current balance */ public double getBalance() { return balance; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started