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

can anyone check to see what im doin wrong with this code im getting the first t

ID: 3685494 • Letter: C

Question

can anyone check to see what im doin wrong with this code im getting the first two output right but im not getting the error of inactivity i need nor the last two output, im thinking its the monthlyProcess method thats wrong, its a quick question please get back to me asap

this is my applicationa

import java.text.DecimalFormat; //allows for the format of the my number output

public class SavingsDemo
{
public static void main (String [] args)
{
//create a DecimalFormat object for formatting output.
DecimalFormat dollar = new DecimalFormat ("#,##0.00");
  
//Create a SavingsAccount object with a $100 balance,
//3% interest rate, and monthly service change
//of $2.50
  
SavingsAccount savings = new SavingsAccount (100.0, 0.03, 2.50);
  
//Display what we've got.
System.out.println (" Balance :$" + dollar.format(savings.getBalance()));
System.out.println ("Number of deposits:" + savings.getDeposit());
System.out.println ("Number of withdrawals:" + savings.getWithdrawals ());
System.out.println (); //blank space
  
//Make some deposits.
savings.setDeposits (25.00);
savings.setDeposits (10.00);
savings.setDeposits (35.00);
  
//Display what weve done so far.
System.out.println (" Balance :$" + dollar.format(savings.getBalance()));
System.out.println ("Number of deposits:" + savings.getDeposit());
System.out.println ("Number of withdrawals:" + savings.getWithdrawals ());
System.out.println (); //blank space
  
//make some withdrawals
savings.setWithdrawal (100.00);
savings.setWithdrawal (50.00);
savings.setWithdrawal (10.00);
savings.setWithdrawal (1.00);
savings.setWithdrawal (1.00);
  
//display what we've done so far.
System.out.println (" Balance :$" + dollar.format(savings.getBalance()));
System.out.println ("Number of deposits:" + savings.getDeposit());
System.out.println ("Number of withdrawals:" + savings.getWithdrawals ());
System.out.println (); //blank space
  
  
//do the monthly process
savings.monthlyProcess ();
  
//Display what we've done so far
System.out.println (" Balance :$" + dollar.format(savings.getBalance()));
System.out.println ("Number of deposits:" + savings.getDeposit());
System.out.println ("Number of withdrawals:" + savings.getWithdrawals ());
System.out.println (); //blank space

}
}   

THIS IS THE SUPERCLASS

/** this class holds the following information about a bank account
balance, number of eeposits this month, number of withdrawals, Annual interest rate, Monthly service charges */

public abstract class BankAccount
{
//define the data fields
private double balance;
private double deposit;
private double withdrawals;
private double annualIR;
private double monthlyCharges;

// constructor
public BankAccount (double myBalance, double myAnnualIR, double monthly)

{
balance = myBalance;
annualIR= myAnnualIR;
deposit = 0;
withdrawals = 0;
monthlyCharges = monthly;
}

//Define methods
public double getBalance ()
{
return balance;
}

public void setBalance (double myBalance)
{
balance = myBalance;
}

public double getDeposit ()
{
return deposit;
}

public void setDeposits (double myDeposit)
{
balance += myDeposit;
deposit +=1;
}

public double getWithdrawals ()
{
return withdrawals;
}

public void setWithdrawal (double myAmount)
{
double amount = myAmount;
balance = balance - amount;
withdrawals += 1;
}

public double calcInterest ()
{
double monthlyRate;
double monthlyInterest;
monthlyRate = (annualIR/12);
monthlyInterest = balance* monthlyRate;
balance = balance + monthlyInterest;
return balance;
  
}

public String getMonthlyProcess (double amount)
{
balance -= monthlyCharges;
calcInterest ();
withdrawals = 0;
deposit = 0;
monthlyCharges = 0;
return "monthly Process: " + balance;
}

protected void addservCharge (double amount)
{
monthlyCharges += amount;
}
  
}

THIS IS THE SUBCLASS

class SavingsAccount extends BankAccount

{

private boolean active;

public SavingsAccount(double accountBalance, double annInterest, double charge)

{

super(accountBalance, annInterest, charge);

//set statues based on balance
if (getBalance () < 25)
{
active = false;
}
else
{
active = true;
}
}
// withdraw: A method that determines whether the account is inactive before a withdrawal is made. ) No withdrawal will be allowed if the account is not active.)
//A withdrawal is then made by calling the superclassversion of the method (assuming it is allowed).

public void withdraw(double amount)

{
//chech balance is less than 25
if (getBalance () < 25)
{
active = false;
}
if(active == false )
{
System.out.println ("Balance is less than 25. The account is inactive");
}
else
{
super.setWithdrawal(amount);
}
  
}   


// deposit: A method that determines whether the account is inactive before a deposit is made.
//If the account is inactive and the deposit brings the accountBalanceabove $25, the account becomes active again. A deposit is then madeby calling the superclass version of the method.

public void deposit(double amount)
{

//Calling super class method
super.setDeposits(amount);
  
//If account is inactive, and balance is greater than equal to 25 , Activating account
if(active==false)
{
  
if(getBalance()>=25)
{
active=true;
}
}
}
// monthlyProcess: Before the superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges.(Don’t forget to check the account accountBalance after the servCharge is taken. If the accountBalance falls below $25, the account becomes inactive.

public void monthlyProcess ()
{
if (getWithdrawals() > 4)
super.getMonthlyProcess (1.00);
}
  


}

MY OUTPUT IS :

Balance :$100.00
Number of deposits:0.0
Number of withdrawals:0.0


Balance :$170.00
Number of deposits:3.0
Number of withdrawals:0.0


Balance :$8.00
Number of deposits:3.0
Number of withdrawals:5.0


Balance :$5.51
Number of deposits:0.0
Number of withdrawals:0.0

CORRECT OUPUT

Balance :$100.00
Number of deposits:0.0
Number of withdrawals:0.0


Balance :$170.00
Number of deposits:3.0
Number of withdrawals:0.0

---Balance is less than $25. the account is inactive
Balance :$20.00
Number of deposits:3.0
Number of withdrawals:2.0


Balance :$17.54
Number of deposits:0.0
Number of withdrawals:0.0

i


  
  

Explanation / Answer

SavingsAccount.java

public class SavingsAccount extends BankAccount {

    private boolean isActive; //If over $25 true, under, false.

    public SavingsAccount(double bal, float ann) {
        super(bal, ann);

        if(bal >= 25.00)
            isActive = true;
    }

    public void withdraw(double withdrawAmount) {
        if(getBalance() < 25.00)
            isActive = false;

        if(isActive)
        {
            super.withdraw(withdrawAmount);
        }
    }

    public void deposit(double depositAmount) {
        if(!isActive)
        {
            if(getBalance() + depositAmount >= 25.00)
            {
                isActive = true;
                super.deposit(depositAmount);
            }
        }
        else
            super.deposit(depositAmount);
    }

    public void monthlyProcess() {
        if(getNumOfWithdrawals() > 4)
        {
            setMonthlyServiceCharges(getNumOfWithdrawals() - 4);
        }
        super.monthlyProcess();

        if(getBalance() < 25.00)
            isActive = false;
    }

    public static void main(String[] args) {
        BankAccount acct = new SavingsAccount(20.00, 0.2f);
    }
}

BankAccount.java
public abstract class BankAccount {

    private double balance;
    private byte numOfDeposits = 0;
    private byte numOfWithdrawals = 0;
    private float annualInterestRate;
    private float monthlyServiceCharges;

    public BankAccount(double bal, float ann) {
        balance = bal;
        annualInterestRate = ann;
    }

    public void deposit(double depositAmount) {
        numOfDeposits++;

        balance += depositAmount;
    }

    public void withdraw(double withdrawAmount) {
        numOfWithdrawals++;

        balance -= withdrawAmount;
    }

    public void calcInterest() {
        float monthlyRate = annualInterestRate/12;
        double interestAmount = balance * monthlyRate;

        balance += interestAmount;
    }

    public void monthlyProcess() {
        balance -= monthlyServiceCharges;
        calcInterest();

        numOfWithdrawals = 0;
        numOfDeposits = 0;
        monthlyServiceCharges = 0;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public byte getNumOfDeposits() {
        return numOfDeposits;
    }

    public void setNumOfDeposits(byte numOfDeposits) {
        this.numOfDeposits = numOfDeposits;
    }

    public byte getNumOfWithdrawals() {
        return numOfWithdrawals;
    }

    public void setNumOfWithdrawals(byte numOfWithdrawals) {
        this.numOfWithdrawals = numOfWithdrawals;
    }

    public float getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(float annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public float getMonthlyServiceCharges() {
        return monthlyServiceCharges;
    }

    public void setMonthlyServiceCharges(float monthlyServiceCharges) {
        this.monthlyServiceCharges = monthlyServiceCharges;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote