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

Design a SavingAccount class that stores a saving account\'s annual rate and bal

ID: 3619475 • Letter: D

Question

Design a SavingAccount class that stores a saving account's annual rate and balance. The class constructor should accept the amount of the savings account's starting balance.The class should also have have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthley interest to the balance. The monthley interest rate is the annual interest rate divided by twelve. To add the monthley interest to the balance, multiplay the monthley interest rate by the balance, and add the result to the balance.
Test the class in a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop[ should then iterate once for every month, performing the following:
a. Ask the user for the amount deposited into the acount during the mounth. Use the class method to add this amount to the account balance.
b. Ask the user for the amount withdrawn from the account during the month. Use the class method to subtract this amount from the account balance.
c. Use the class method to calculate the monthley interest.
After the last iteration, the total amount of withdrawals, and the total interest earned.

Explanation / Answer

please rate - thanks

import java.util.*;
public class SavingAccountTest
{public static void main(String[] args)
{double balance,interest,withdraw,deposit;
int months,i;
Scanner in=new Scanner(System.in);
SavingAccount account = new SavingAccount();
System.out.println("Enter the starting balance: ");
balance=in.nextDouble();
account.Balance(balance);
System.out.println("Enter the annual interest rate: ");
interest=in.nextDouble();
account.setInterestRate(interest);
System.out.println("Enter how many months the account has been open: ");
months=in.nextInt();
for(i=0;i<months;i++)
{System.out.println("Enter amount deposited month "+(i+1));
deposit=in.nextDouble();
account.deposit(deposit);
System.out.println("Enter amount to withdraw month "+(i+1));
withdraw=in.nextDouble();
account.withdraw(withdraw);
account.LastInterest();
}

System.out.printf("Total deposited $ %.2f ",account.getDeposits());
System.out.printf("Total withdrawn $ %.2f ",account. getWithdrawals());
System.out.printf("Interest earned $ %.2f ",account.getInterest());
System.out.printf("Ending balance $%.2f ",account.getBalance() );
}
}

--------------------------------------------

public class SavingAccount
{private double balance,annual,month,deposits,withdraws,earned;
public void Balance(double b)
{ balance=b;
}
public void deposit(double a)
{balance+=a;
deposits+=a;
}
public void withdraw(double a)
{ balance-=a;
withdraws+=a;
}
public void LastInterest()
{double interest,month;
month=annual/12./100.;
interest=month*balance;
balance+=interest;
earned+=interest;
}
public void setInterestRate(double i)
{ annual=i;
}
public double getBalance()
{return balance;
}
public double getDeposits()
{return deposits;
}
public double getWithdrawals()
{return withdraws;
}
public double getInterest()
{return earned;
}
}