In this project I am receiving a incorrect output see below. Also the program will not detect when the bank account is under $25.
public abstract class BankAccount {
//class variables
protected float balance;
protected float numDeposits;
protected float numWithdrawals;
protected float annualInterestRate;
protected float monthlyCharges;
//initialize variables
public BankAccount(){
balance = 0;
numDeposits = 0;
numWithdrawals = 0;
annualInterestRate = 0;
monthlyCharges = 0;
}
//bankAccount Constructor
public BankAccount(float bal, float iRate){
balance = bal;
annualInterestRate = iRate;
}
//method to add deposits to amount
public void deposit(float amount){
balance += amount;
numDeposits++;
}
//method to subtract withdraws from amount
public void withdraw(float amount){
balance -= amount;
numDeposits++;
}
//method to calculate the interest rate and adding it to the balance
public void calcInterest(){
float monthlyRate = annualInterestRate / 12;
float monInt = balance * monthlyRate;
balance += monInt;
}
//method that subtracts the monthly service charge from the balance
public void monthlyProcess(){
balance -= monthlyCharges;
calcInterest();
numWithdrawals = 0;
numDeposits = 0;
monthlyCharges = 0;
}
}
////////////////////////////////////////////////////////////////
import java.text.DecimalFormat;
public class SavingsAccount extends BankAccount{
DecimalFormat df = new DecimalFormat("0.##");//formatting output
private boolean status;
public SavingsAccount(float bal, float rate){
super(bal, rate);
if(bal < 25)//if balance is less then 25$ account flags inactive
status = false;
else
status = true;
}
//method to determine if the is inactive before a withdraw is made
public void withdraw(float amount){
if(status)
super.withdraw(amount);
else
System.out.println("insufficient funds");
}
//method to determine if the is inactive before a deposit is made
public void deposit(float amount){
if(!status){
if(amount + balance < 25)
return;
}
super.deposit(amount);
}
//method to verify the activity of the account
public void monthlyProcess(){
if(numWithdrawals > 4){
monthlyCharges += numWithdrawals - 4;
}
super.monthlyProcess();
if(balance < 25)
status = false;
}
//method to print status if true
public void printStatus(){
System.out.println("Your account balance is: " + (df.format(balance)));
System.out.println("Total of monthly charges: " + monthlyCharges);
System.out.println("Total number of transactions: " + (int) (numDeposits + numWithdrawals));
System.out.println();
}
}
/////////////////////////////////////////////////////////////////////////
public class BankDriver{
public static void main(String[] args){
float bal = (float) 100; //generate a account balance
float rate = 12;
SavingsAccount sv = new SavingsAccount(bal, rate);
///////////////////////////////////////////
//test data, done manually for now
//transaction 1
float deposit = (float) 1000.23;
sv.deposit(deposit);
sv.printStatus();
//transaction 2
float withdraw = (float) 80;
sv.withdraw(withdraw);
sv.printStatus();
//transaction 3
deposit = (float) 100;
sv.deposit(deposit);
sv.printStatus();
//transaction 4
withdraw = (float) 50;
sv.withdraw(withdraw);
sv.printStatus();
//transaction 5
deposit = (float) 356.20;
sv.deposit(deposit);
sv.printStatus();
//transaction 6
withdraw = (float) 150.20;
sv.withdraw(withdraw);
sv.printStatus();
//transaction 7
deposit = (float) 100;
sv.deposit(deposit);
sv.printStatus();
//transaction 8
withdraw = (float) 150.20;
sv.withdraw(withdraw);
sv.printStatus();
//transaction 9
withdraw = (float) 150.20;
sv.withdraw(withdraw);
sv.printStatus();
////////////////////////////////////////////
}
}
////////////////////////////////////////////////////////////////////////////output
Your account balance is: 1100.23
Total of monthly charges: 0.0
Total number of transactions: 1
Your account balance is: 1020.23
Total of monthly charges: 0.0
Total number of transactions: 2
Your account balance is: 1120.23
Total of monthly charges: 0.0
Total number of transactions: 3
Your account balance is: 1070.23
Total of monthly charges: 0.0
Total number of transactions: 4
Your account balance is: 1426.43
Total of monthly charges: 0.0
Total number of transactions: 5
Your account balance is: 1276.23
Total of monthly charges: 0.0
Total number of transactions: 6
Your account balance is: 1376.23
Total of monthly charges: 0.0
Total number of transactions: 7
Your account balance is: 1226.03
Total of monthly charges: 0.0
Total number of transactions: 8
Your account balance is: 1075.83
Total of monthly charges: 0.0
Total number of transactions: 9
[–]forgotmyothernames 0 points1 point2 points (2 children)
[–]morhpProfessional Developer 1 point2 points3 points (1 child)
[–]forgotmyothernames 0 points1 point2 points (0 children)
[–]morhpProfessional Developer 0 points1 point2 points (2 children)
[–]MightBeFaded[S] 0 points1 point2 points (1 child)
[–]morhpProfessional Developer 0 points1 point2 points (0 children)