a) Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors.
b) Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, set minimum balance, retrieve minimum balance, set service charges, retrieve service charges, post interest, verify if the balance is less than the minimum balance, write a check, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
c) Every bank offers a savings account. Derive the class savingsAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposits, and withdraws money. In addition to the operations inherited from the base class, this class should provide the following operations: set interest rate, retrieve interest rate, post interest, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
Write a program to test your classes designed in parts (b) and (c).
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
Solution
BankAccount.java
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public abstract class BankAccount {
private String accountName;
private int accountNumber;
private double accountBalance;
public BankAccount() {
System.out.println("Welcome, to the new bank");
}
public BankAccount(String accountName, int accountNumber, double accountBalance) {
this.accountName = accountName;
this.accountNumber = accountNumber;
this.accountBalance = accountBalance;
}
//define method to get customer's Account Name
public String getAccountName() {
return accountName;
}
//define method to set customer's Account Name
public void setAccountName(String accountName) {
this.accountName = accountName;
}
//define method to get customer's Account Number
public int getAccountNumber() {
return accountNumber;
}
//define method to set customer's Account Number
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
//define method to get customer's Account Balance
public double getAccountBalance() {
return accountBalance;
}
//define method to set customer's Account Balance
public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}
//define method for customer's withdrawal
public void withdrawal(double amountWithDrawn)
{
if (accountBalance > 0.0){
accountBalance -= amountWithDrawn;
}
else {
System.out.println("Sorry, you currently have no money in your account!");
}
}
//define method for customer's account deposit
public double deposit(double amountDeposited) {
return accountBalance += amountDeposited;
}
//define method to print customer's account information
@Override
public String toString() {
return "Bank Account Information" + "\nAccount Name: " + getAccountName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Balance: " + getAccountBalance();
}
}
CheckingAccount.java
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public class CheckingAccount extends BankAccount{
private double interestRate;
private double minimumBalance;
private double serviceCharge;
public CheckingAccount(String accountName, int accountNumber, double accountBalance, double interestRate, double minimumBalance, double serviceCharge) {
super(accountName, accountNumber, accountBalance);
this.interestRate = interestRate;
this.minimumBalance = minimumBalance;
this.serviceCharge = serviceCharge;
}
//define method to get Interest Rate
public double getInterestRate() {
return interestRate;
}
//define method to set Interest Rate
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
//define method to get Minimum Balance
public double getMinimumBalance() {
return minimumBalance;
}
//define method to set Minimum Balance
public void setMinimumBalance(double minimumBalance) {
this.minimumBalance = minimumBalance;
}
//define method to get Service Charge
public double getServiceCharge() {
return serviceCharge;
}
//define method to set Service Charge
public void setServiceCharge(double serviceCharge) {
this.serviceCharge = serviceCharge;
}
//define method to add Interest Rate to Account Balance
public void postInterestRate() {
setAccountBalance(getAccountBalance() + this.interestRate);
}
//define method to check Balance Status
public boolean isAccountBalanceLessThanMinimumBalance() {
if(getAccountBalance() < this.minimumBalance){
return true; // Account balance is lower than minimum balance
}
else{
return false; // Account balance is good to go
}
}
//define method to print Balance Status
public void printBalanceStatus() {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Account balance is lower than minimum balance");
}
else{
System.out.println("Account balance is good to go");
}
}
//define method to write a check
public void writeCheck(double checkAmount) {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Checking Transaction Denied! Account balance is currently lower than minimum balance!");
}
else
{
if((getAccountBalance() - checkAmount) < this.minimumBalance){
setAccountBalance(getAccountBalance() - getServiceCharge());
System.out.println("You've been charged " + getServiceCharge() + " for service charges.");
}
else
{
setAccountBalance(getAccountBalance() - checkAmount);
System.out.println("Checking Transaction Successful! " + checkAmount + " Checked out.");
}
}
}
//define method to withdraw from account
public void withdrawal(double amountWithDrawn) {
if(isAccountBalanceLessThanMinimumBalance()){
System.out.println("Withdrawal Transaction Denied! Account balance is currently lower than minimum balance!");
}
else
{
if((getAccountBalance() - amountWithDrawn) < this.minimumBalance)
{
setAccountBalance(getAccountBalance() - getServiceCharge());
System.out.println("You've been charged " + getServiceCharge() + " for service charges.");
}
else
{
setAccountBalance(getAccountBalance() - amountWithDrawn);
System.out.println("Withdrawal Transaction Successful! " + amountWithDrawn + " withdrawn from account.");
}
}
}
//define method to print customer's account information
@Override
public String toString() {
return "Bank Account Information for Checking Account" + "\nAccount Name: " + getAccountName() + "\nAccount Number: " + getAccountNumber() + "\nAccount Balance: " + getAccountBalance() + "\nInterest Rate: " + interestRate + "\nMinimum Balance: " + minimumBalance + "\nService Charge: " + serviceCharge;
}
}
SavingsAccount.java
package bankingsystem;
/**
*
* @author Archangel Macsika
*/
public class BankingSystem {
public static void main(String[] args) {
// Program for CheckingAccount class
CheckingAccount checkAcc = new CheckingAccount("Nsikak Imoh", 123456789, 10000.95, 100.50, 2000.00, 5.00);
System.out.println(checkAcc.getInterestRate());
checkAcc.setInterestRate(200.89);
checkAcc.postInterestRate();
System.out.println(checkAcc.getMinimumBalance());
checkAcc.setMinimumBalance(5000.00);
System.out.println(checkAcc.getServiceCharge());
checkAcc.setServiceCharge(10.99);
checkAcc.printBalanceStatus();
checkAcc.writeCheck(8000.00);
checkAcc.deposit(20000.00);
checkAcc.withdrawal(10000.00);
System.out.println(checkAcc.toString());
System.out.println("\n\n");
// Program for SavingsAccount class
SavingsAccount savingsAcc = new SavingsAccount("Archangel Macsika", 987654321, 20000.95, 50.50);
System.out.println(savingsAcc.getInterestRate());
savingsAcc.setInterestRate(250.85);
savingsAcc.postInterestRate();
savingsAcc.withdrawal(10000.00);
savingsAcc.deposit(20000.00);
System.out.println(savingsAcc.toString());
}
}
Main Class
package bankingsystem;
/**
*
* @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
