Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet with their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another type of account that is used to save money for the long term is certificate of deposit (CD). In this programming exercise, you use abstract classes to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next.
Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate.
Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.
Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. Penalty for early withdrawal is stiff.
Write the definitions of the classes described in this programming exercise and a program to test your classes.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
Problem to be Solved and Solution

Note that the classes bankAccount
and checkingAccount
are abstract. That is, we cannot instantiate objects of these classes. The other classes in the figure are not abstract.
bankAccount:
Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name
, accountNumber
, and balance
should be declared in the abstract class bankAccount
. Some operations common to all types of accounts are retrieve account owner’s name, account number, and account balance; make deposits; withdraw money; and create monthly statement. So include methods to implement these operations. Some of these methods will be abstract.
BankAccount.java
package banks;
/**
*
* @author Archangel Macsika
*/
public abstract class BankAccount {
private String name;
private int accountNumber;
private double balance;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void withdrawal(double amountWithDrawn)
{
if (balance > 0.0){
if((balance - amountWithDrawn) < 0.0) {
System.out.println("Sorry, your balance is insufficient to perform this transaction!");
}else{
balance -= amountWithDrawn;
}
}
else {
System.out.println("Sorry, you currently have no money in your account!");
}
}
public double deposit(double amountDeposited) {
return balance += amountDeposited;
}
public abstract void createMonthlyStatement();
checkingAccount:
A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the abstract method writeCheck
to write a check.
CheckingAccount.java
package banks;
/**
*
* @author Archangel Macsika
*/
public abstract class CheckingAccount extends BankAccount {
public abstract void writeCheck(double amount);
}
certificateOfDeposit:
A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month.
CertificateOfDeposit.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class CertificateOfDeposit extends BankAccount {
private int numberOfCDMaturityMonths;
private double interestRate;
private int currentCDMonth;
public int getNumberOfCDMaturityMonths() {
return numberOfCDMaturityMonths;
}
public void setNumberOfCDMaturityMonths(int numberOfCDMaturityMonths) {
this.numberOfCDMaturityMonths = numberOfCDMaturityMonths;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public int getCurrentCDMonth() {
return currentCDMonth;
}
public void setCurrentCDMonth(int currentCDMonth) {
this.currentCDMonth = currentCDMonth;
}
@Override
public void createMonthlyStatement(){
System.out.println("\nMonthly Statement\nAccount Name: " + getName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Type: Certificate of Deposit Account" + "\nInterest for the month: " + getInterestRate() +"\nAccount Balance: " + (getBalance() + getInterestRate()) + "\nCurrent CD Month is " + getCurrentCDMonth() + " out of " + getNumberOfCDMaturityMonths());
}
}
savingsAccount:
A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest.
SavingsAccount.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class SavingsAccount extends BankAccount {
private double interestRate;
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
@Override
public void createMonthlyStatement() {
System.out.println("\nMonthly Statement\nAccount Name: " + getName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Type: Savings Account" + "\nInterest for the month: " + getInterestRate() +"\nAccount Balance: " + (getBalance() + getInterestRate()));
}
}
serviceChargeChecking:
A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and methods in this class.
ServiceChargeChecking.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class ServiceChargeChecking extends CheckingAccount {
private double serviceCharge;
private int limit;
public static final double INTEREST = 0.0;
public static final double MININMUMBALANCE = 0.0;
public double getServiceCharge() {
return serviceCharge;
}
public void setServiceCharge(double serviceCharge) {
this.serviceCharge = serviceCharge;
}
public static double getINTEREST() {
return INTEREST;
}
public static double getMININMUMBALANCE() {
return MININMUMBALANCE;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
@Override
public void writeCheck(double amount) {
if(getLimit() <= 0 ){
System.out.println("You've exhausted the check limit for this month");
}else{
setBalance((getBalance() - amount));
setLimit(getLimit() - 1);
System.out.println("Checking Transaction Successful! " + amount + " Checked out.");
}
}
@Override
public void createMonthlyStatement() {
System.out.println("\nMonthly Statement\nAccount Name: " + getName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Type: Service Checking Account" + "\nService Charge for the month: " + getServiceCharge() +"\nAccount Balance: " + (getBalance() - getServiceCharge()));
}
}
noServiceChargeChecking:
A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance.
NoServiceChargeChecking.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class NoServiceChargeChecking extends CheckingAccount {
private double interestRate;
private static final double MININMUMBALANCE = 10.50;
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public static double getMININMUMBALANCE() {
return MININMUMBALANCE;
}
//define method to check Balance Status
public boolean isAccountBalanceLessThanMinimumBalance() {
if(getBalance() < getMININMUMBALANCE()){
return true; // Account balance is lower than minimum balance
}
else{
return false; // Account balance is good to go
}
}
@Override
public void writeCheck(double amount) {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Checking Transaction Denied! Account balance is currently lower than minimum balance!");
}
else
{
if((getBalance() - amount) < getMININMUMBALANCE()){
System.out.println("Checking Transaction Denied due to insufficient amount!");
}
else
{
setBalance(getBalance() - amount);
System.out.println("Checking Transaction Successful! " + amount + " Checked out.");
}
}
}
@Override
public void createMonthlyStatement() {
System.out.println("\nMonthly Statement\nAccount Name: " + getName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Type: No Service Checking Account" + "\nInterest for the month: " + getInterestRate() +"\nAccount Balance: " + (getBalance() + getInterestRate()));
}
}
highInterestChecking:
A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account.
HighInterestChecking.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class HighInterestChecking extends NoServiceChargeChecking {
private double interestRate;
private static final double MININMUMBALANCE = 21.50;
@Override
public double getInterestRate() {
return this.interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public static double getMININMUMBALANCE() {
return MININMUMBALANCE;
}
}
highInterestSavings:
A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance.
HighInterestSavings.java
package banks;
/**
*
* @author Archangel Macsika
*/
public class HighInterestSavings extends SavingsAccount {
private static final double MININMUMBALANCE = 10.50;
public static double getMININMUMBALANCE() {
return MININMUMBALANCE;
}
@Override
public double getInterestRate() {
return super.getInterestRate() * 2; //To change body of generated methods, choose Tools | Templates.
}
}
Main Class
package banks;
/**
*
* @author Archangel Macsika
*/
public class Banks {
public static void main(String[] args) {
// Declare variables for common values
double accountBalance, standardServiceCharge, highServiceCharge, standardInterestRate, highInterestRate;
String accountName = "Nsikak Imoh";
int accountNumber = 1234567890;
accountBalance = 1000.50;
standardServiceCharge = 100.00;
standardInterestRate = 50.50;
highInterestRate = standardInterestRate * 2;
int limit = 3;
// Program for ServiceChargeChecking Class
ServiceChargeChecking scc = new ServiceChargeChecking();
scc.setName(accountName);
scc.setAccountNumber(accountNumber);
scc.setBalance(accountBalance);
scc.setServiceCharge(standardServiceCharge);
scc.setLimit(limit);
scc.writeCheck(800.00);
scc.createMonthlyStatement();
// Program for NoServiceChargeChecking Class
NoServiceChargeChecking nscc = new NoServiceChargeChecking();
nscc.setName(accountName);
nscc.setAccountNumber(accountNumber);
nscc.setBalance(accountBalance);
nscc.setInterestRate(standardInterestRate);
nscc.writeCheck(800.00);
nscc.createMonthlyStatement();
// Program for HighInterestChecking Class
HighInterestChecking hic = new HighInterestChecking();
hic.setName(accountName);
hic.setAccountNumber(accountNumber);
hic.setBalance(accountBalance);
hic.setInterestRate(highInterestRate);
hic.writeCheck(800.00);
hic.createMonthlyStatement();
// Program for SavingsAccount Class
SavingsAccount sa = new SavingsAccount();
sa.setName(accountName);
sa.setAccountNumber(accountNumber);
sa.setBalance(accountBalance);
sa.setInterestRate(standardInterestRate);
sa.deposit(2000.00);
sa.withdrawal(3500.50);
sa.createMonthlyStatement();
// Program for HighInterestSavings Class
HighInterestSavings his = new HighInterestSavings();
his.setName(accountName);
his.setAccountNumber(accountNumber);
his.setBalance(accountBalance);
his.setInterestRate(highInterestRate);
his.createMonthlyStatement();
// Program for CertificateOfDeposit Class
CertificateOfDeposit cod = new CertificateOfDeposit();
cod.setName(accountName);
cod.setAccountNumber(accountNumber);
cod.setBalance(accountBalance);
cod.setInterestRate(standardInterestRate);
cod.setNumberOfCDMaturityMonths(10);
cod.setCurrentCDMonth(4);
cod.createMonthlyStatement();
}
}
Output of the Java Bank Account Program

