Design and implement the following 3 classes with the exact fields and methods (
ID: 3806678 • Letter: D
Question
Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract class named BankAccount (java file called Ban unt. Eva Filed/Method Description Dalanc The bank account balance NumberDeposits The number of deposits this month Number Withdrawals The number of withdrawals this month IAnnualinterestRate IThe annual interest rat Monthly Service Charge The monthly service charge Bank Account A constructor method that accepts as arguments the balance and the annual interest rate SehMonthly Service Charges A method that accepts the monthly service charges as an argument and set the field value GetBalance Amethod that returns the bank account balance GeINumberoeposits A method that returns the number of deposits this month GetNumberwihdrawals Amethod that returns the number of withdrawals this month GetAnnualinterestRate Amethod that returns the annualinterest rat GetMonthlyServicecharge Amethod that returns the monthly service charge Deposit A method that accepts the amount of the deposit as an argument, add the value of that argument to the account balance and increment the variable holding the number of deposits. Withdrawal A method that accepts the amount of the withdrawal as an argument, subtracts that argument value from the balance, and increment the value holding the number of withdrawals Calculateinteres A method that updates the balance by calculating the monthly interest earned by the account and adding this to the balance (Balance Monthly Interest Balance Balance interest Monthlylnterest) Monthly Process A method that subtracts the monthly service charges from the balance, callas the calculatelnterest method to calculate the interest, and then sets to 0 the variables for NumberDeposits, NumberWithdrawals, and MonthlyServiceChargeExplanation / Answer
PROGRAM CODE:
BankAccount.java
package simple;
public abstract class BankAccount {
double balance;
int NumberDeposits;
int NumberWithdrawals;
double AnnualInterestRate;
double MonthlyServiceCharge;
public BankAccount(double bal, double interestrate) {
this.balance = bal;
this.AnnualInterestRate = interestrate;
this.NumberDeposits = 0;
this.NumberWithdrawals = 0;
this.MonthlyServiceCharge = 0.0;
}
public void setMonthlyServiceCharge(double charge) {
this.MonthlyServiceCharge = charge;
}
public double getBalance() {
return balance;
}
public int getNumberDeposits() {
return NumberDeposits;
}
public int getNumberWithdrawals() {
return NumberWithdrawals;
}
public double getAnnualInterestRate() {
return AnnualInterestRate;
}
public double getMonthlyServiceCharge() {
return MonthlyServiceCharge;
}
public void Deposit(double amount)
{
balance += amount;
NumberDeposits++;
}
public void Withdrawal(double amount)
{
balance -= amount;
NumberWithdrawals++;
}
public void CalculateInterest()
{
double monthlyInterestRate = balance *(AnnualInterestRate/12);
balance += monthlyInterestRate;
}
public void MonthlyProcess()
{
balance -= MonthlyServiceCharge;
CalculateInterest();
this.NumberDeposits = 0;
this.NumberWithdrawals = 0;
this.MonthlyServiceCharge = 0.0;
}
}
SavingsAccount.java
package simple;
public class SavingsAccount extends BankAccount{
boolean status;
public SavingsAccount(double bal, double interestrate, double monthlyCharge) {
super(bal, interestrate);
super.setMonthlyServiceCharge(monthlyCharge);
if(balance < 25)
status = false;
else status = true;
}
@Override
public void Deposit(double amount) {
// TODO Auto-generated method stub
super.Deposit(amount);
if(balance >= 25)
status = true;
}
@Override
public void Withdrawal(double amount) {
// TODO Auto-generated method stub
super.Withdrawal(amount);
if(balance < 25)
status = false;
}
@Override
public void MonthlyProcess() {
if(NumberWithdrawals > 4)
super.setMonthlyServiceCharge(getMonthlyServiceCharge() + (NumberWithdrawals-4));
super.MonthlyProcess();
}
}
BankAccountTester.java
package simple;
public class BankAccountTester {
public static void main(String args[])
{
SavingsAccount sa = new SavingsAccount(20, 5, 5);
sa.Deposit(30);
sa.Deposit(100);
sa.Withdrawal(20);
System.out.println("Before monthly process: ");
System.out.println("Balance: " + sa.getBalance());
System.out.println("Number of Deposits: " + sa.getNumberDeposits());
System.out.println("Number of Withdrawals: " + sa.getNumberWithdrawals());
System.out.println("Annual Interest Rate: " + sa.getAnnualInterestRate());
System.out.println("Monthly Service Charge: " + sa.getMonthlyServiceCharge());
System.out.println(" After monthly process: ");
sa.MonthlyProcess();
System.out.println("Balance: " + sa.getBalance());
System.out.println("Number of Deposits: " + sa.getNumberDeposits());
System.out.println("Number of Withdrawals: " + sa.getNumberWithdrawals());
System.out.println("Annual Interest Rate: " + sa.getAnnualInterestRate());
System.out.println("Monthly Service Charge: " + sa.getMonthlyServiceCharge());
}
}
OUTPUT:
Before monthly process:
Balance: 130.0
Number of Deposits: 2
Number of Withdrawals: 1
Annual Interest Rate: 5.0
Monthly Service Charge: 5.0
After monthly process:
Balance: 177.08333333333334
Number of Deposits: 0
Number of Withdrawals: 0
Annual Interest Rate: 5.0
Monthly Service Charge: 0.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.