Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design an abstract class called BankAccount. The account should store the balanc

ID: 3530926 • Letter: D

Question

Design an abstract class called BankAccount. The account should store the balance and account number of the customer. Suppose that account number is of the type int and the balance is of the type double. Your class should, at least, provide the following operations: set account number retrieve account number retrieve balance deposit and withdraw money print account information. Add appropriate constructors Every bank offers a CheckingAccount. The class should be extended from the BankAccount class. The class will inherit members to store the account number and balance from the superclass. A customer with a checking account usually receives interest, maintains a minimum balance, and pays service charges if the balance falls below a minimum balance. Add variables to hold the additional information. In addition to the inherited methods, the class should provide the following methods: set/retrieve interest rate (2 separate methods) set/retrieve minimum balance set/retrieve service charges post interest verify if the balance is less than the minimum balance write a check withdraw (overrides the superclass) print account information Add appropriate constructors Every bank also offers a SavingsAccount. This class extends the BankAccount class. The savings account customer typically receives interest, makes deposits and withdraws money. This class should provide the following methods: set/retrieve interest rates (2 separate methods) post interest withdraw (override the base) Print account information Add appropriate constructors. Write a program to demonstrate your classes.

Explanation / Answer

This is the exact answer for your que..So check it out...


BamkAccount Class


public abstract class BankAccount
{
// class variable so that each account has a unique number
protected static int numberOfAccounts = 100001;
// current balance in the account
private double balance;
// name on the account
private String owner;
// number bank uses to identify account
private String accountNumber;

//default no-arg constructor
public BankAccount()
{
balance = 0;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}

//standard constructor
public BankAccount(String name, double amount)
{
owner = name;
balance = amount;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}

//copy constructor
public BankAccount(BankAccount oldAccount, double amount)
{
owner = oldAccount.owner;
balance = amount;
accountNumber = oldAccount.accountNumber;
}

//Method "deposit" allows you to add money to the account
public void deposit(double amount)
{
balance = balance + amount;
}

//Method "withdraw" allows you to remove money from the account if enough money
//returns true if the transaction was completed
//returns false if the there was not enough money
public boolean withdraw(double amount)
{
boolean completed = true;
if (amount <= balance)
{
balance = balance - amount;
}
else
{
completed = false;
}
return completed;
}

//accessor method to get balance
public double getBalance()
{
return balance;
}

//accessor method to get owner
public String getOwner()
{
return owner;
}

//accessor method to get account number
public String getAccountNumber()
{
return accountNumber;
}

//mutator method to change the balance
public void setBalance(double newBalance)
{
balance = newBalance;
}

//mutator method to change the account number
public void setAccountNumber(String newAccountNumber)
{
accountNumber = newAccountNumber;
}
}

Check Account Class



public class CheckingAccount extends BankAccount
{
//It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents.


public static final double FEE = 0.15;

// Write a constructor that takes a name and an initial amount as parameters.
public CheckingAccount(String name, double initialAmount)
{
// It should call the constructor for the superclass.
super(name, initialAmount);
/* It should initialize accountNumber to be the current value in accountNumber concatenated with -10
//(All checking accounts at this bank are identified by the extension -10). There can be only one checking account
//for each account number.Remember since accountNumber is a private member in BankAccount, it must be changed through a
mutator method.*/
setAccountNumber(getAccountNumber()+"-10");
}
/* Write a new instance method, withdraw, that overrides the withdraw method in the superclass.
This method should take the amount to withdraw, add to it the fee for check clearing, and call
the withdraw method from the superclass. Remember that to override the method, it must have the
same method heading.Notice that the withdraw method from the superclass returns true or false
depending if it was able to complete the withdrawal or not. The method thatoverrides it must also
return the same true or false that was returned from thecall to the withdraw method from the superclass.*/


public boolean withdraw(double amount)
{
return super.withdraw(amount+FEE);
}
}

SavingsAccount Class



public class SavingsAccount extends BankAccount{

private double rate = .025;
private int savingsNumber =0;
private String accountNumber;
public SavingsAccount(String name,int balance) {
super(name,balance);
this.accountNumber = super.getAccountNumber()+"-"+savingsNumber;
}
public SavingsAccount(SavingsAccount s,int balance)
{
super(s,balance);
this.setSavingsNumber(s.getSavingsNumber()+1);
this.setAccountNumber(super.getAccountNumber()+"-"+this.getSavingsNumber());
}
public double getRate() {
return rate;
}

public void setRate(double rate) {
this.rate = rate;
}

public int getSavingsNumber() {
return savingsNumber;
}

public void setSavingsNumber(int savingsNumber) {
this.savingsNumber = savingsNumber;
}

public String getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}

public void postInterest()
{
double intrestPerMonth=(this.getBalance() * .025 )/12;
this.setBalance(this.getBalance()+intrestPerMonth);
}


}


Account Driver Class


import java.text.*; // to use Decimal Format
public class AccountDriver
{
public static void main(String[] args)
{
double put_in = 500;
double take_out = 1000;
DecimalFormat myFormat;
String money;
String money_in;
String money_out;
boolean completed;
// to get 2 decimals every time
myFormat = new DecimalFormat("#.00");
//to test the Checking Account class
CheckingAccount myCheckingAccount = new CheckingAccount("Benjamin Franklin", 1000);
System.out.println ("Account Number " + myCheckingAccount.getAccountNumber() +
" belonging to " + myCheckingAccount.getOwner());
money = myFormat.format(myCheckingAccount.getBalance());
System.out.println ("Initial balance = $" + money);
myCheckingAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(myCheckingAccount.getBalance());
System.out.println ("After deposit of $" + money_in + ", balance = $" + money);
completed = myCheckingAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(myCheckingAccount.getBalance());
if (completed)
{
System.out.println("After withdrawal of $" + money_out + ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $" + money_out +
", balance = $" + money);
}
System.out.println();
//to test the savings account class
SavingsAccount yourAccount = new SavingsAccount ("William Shakespeare", 400);
System.out.println ("Account Number " + yourAccount.getAccountNumber() +
" belonging to " + yourAccount.getOwner());
money = myFormat.format(yourAccount.getBalance());
System.out.println ("Initial balance = $" + money);
yourAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(yourAccount.getBalance());
System.out.println ("After deposit of $" + money_in + ", balance = $" + money);
completed = yourAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(yourAccount.getBalance());
if (completed)
{
System.out.println("After withdrawal of $" + money_out + ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $" + money_out +
", balance = $" + money);
}
yourAccount.postInterest();
money = myFormat.format(yourAccount.getBalance());
System.out.println ("After monthly interest has been posted," +
"balance = $" + money);
System.out.println();
//to test the copy constructor of the savings account class
SavingsAccount secondAccount = new SavingsAccount (yourAccount,5);
System.out.println ("Account Number " + secondAccount.getAccountNumber()+
" belonging to " + secondAccount.getOwner());
money = myFormat.format(secondAccount.getBalance());
System.out.println ("Initial balance = $" + money);
secondAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(secondAccount.getBalance());
System.out.println ("After deposit of $" + money_in + ", balance = $" + money);
secondAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(secondAccount.getBalance());
if (completed)
{
System.out.println("After withdrawal of $" + money_out + ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $" +
money_out + ", balance = $" + money);
}
System.out.println();
//to test to make sure new accounts are numbered correctly
CheckingAccount yourCheckingAccount = new CheckingAccount ("Isaac Newton", 5000);
System.out.println ("Account Number " + yourCheckingAccount.getAccountNumber() +
" belonging to " + yourCheckingAccount.getOwner());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote