Question
The second class is Account.It must have a constructor plus a method that corresponds to each of the four buttons in the GUI. It must also incorporate logic to deduct a service charge of $1.50 when more than four total withdrawals are made from either account. Note that this means, for example, if two withdrawals are made from the checking and two from the savings, any withdrawal from either account thereafter incurs the service charge. The method that performs the withdrawals must throw an InsufficientFunds exception whenever an attempt is made to withdraw more funds than are available in the account. Note that when service charges apply, there must also be sufficient funds to pay for that charge.
The third class is InsufficientFunds, which is a user defined checked exception.
Be sure to follow good programming style, which means making all instance and class variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough scenarios to completely test the program.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
public class Account {private double balance;
private int withdrawnCounter;
public Account(double balance) {
this.balance = balance;
withdrawnCounter = 0;
}
public void withdraw(double amount) throws InsufficientFunds{
if (amount % 20 != 0 ) {
throw new InsufficientFunds("The amount isn't in increments of $20");
}
if ((withdrawnCounter + 1) % 4 == 0 ) {
amount += 1.5;
}
if (amount > balance ) {
throw new InsufficientFunds("An attempt is made to withdraw more funds than are available in the account");
}
balance -= amount;
withdrawnCounter++;
}...