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

----------------------------------------- SavingAccount ------------------------

ID: 3614027 • Letter: #

Question

-----------------------------------------
SavingAccount
-----------------------------------------
- balance : double
- annualInterestRate : double
- lastInterest : double
------------------------------------------
+SavingAccount(bal: double, rate: double)
+deposit(amount: double):void
+withdraw(amount: double):void
+addInterest(): void
+getBalance():double
+getInterestRate(): double
+getLastInterest(): double
------------------------------------------


a.
Ask the user for the amount deposited into the account during themonth. Use the class method to add this amount tot the accountbalance.
b.
Ask the user for the amount withdrawn from the account during themonth. Use the class method to subtract this amount from theaccount balance.
c.
Use the class method to calculate the monthly interest.


two output of example..


Enter the savings account's starting balance: 100
Enter the savings account's annual interest rate: .12
How many months have passed since the account was opened? 1
Enter the amount deposited during month 1: 100
Enter the amount withdrawn during month 1: 0
Total deposited: $100.00
Total withdrawn: $0.00
Interest earned: $2.00
Ending balance: $202.00


Enter the savings account's starting balance: 1000
Enter the savings account's annual interest rate: .12
How many months have passed since the account was opened? 3
Enter the amount deposited during month 1: 100
Enter the amount withdrawn during month 1: 0
Enter the amount deposited during month 2: 110
Enter the amount withdrawn during month 2: 10
Enter the amount deposited during month 3: 120
Enter the amount withdrawn during month 3: 20
Total deposited: $330.00
Total withdrawn: $30.00
Interest earned: $36.34
Ending balance: $1,336.34

Explanation / Answer

import java.io.*; import java.util.*; import java.lang.*; public class SavingsAccount{ public double balance=0.0; public double annualInterestRate = 0; public double lastInterest =0.0; public SavingsAccount( double bal, double rate) {    this.balance =bal;    this.annualInterestRate = rate; } public void deposit(double amount) {    balance += amount; } public void withdraw(double amount) {    //if((balance -amount) >0)        balance = balance -amount;    //else        //System.out.println("Balancein the savings account is less than withdrawl amount"); } public void addInterest() {    lastInterest = (annualInterestRate/12) *balance * 0.01;    balance += lastInterest; } public double getBalance() {    return balance; } public double getInterestRate() {       return annualInterestRate; } public double getInterest() {       return lastInterest; } public static void main(String[] args){ double bal=0, irate=0; int nMonths=0;    try    {        System.out.print("Enter thesavings account's starting balance: ");        bal = Double.parseDouble(new BufferedReader(newInputStreamReader(System.in)).readLine());               System.out.print("Enter thesavings account's annual interest rate: ");        irate = Double.parseDouble(new BufferedReader(newInputStreamReader(System.in)).readLine());               System.out.print("How manymonths have passed since the account was opened? ");        nMonths = Integer.parseInt(new BufferedReader(newInputStreamReader(System.in)).readLine());    }    catch (Exception e)    {        e.printStackTrace();    }       SavingsAccount sa= new SavingsAccount(bal,irate);    int counter =1;    double amountDep=0, amountWithdrawn=0, totDep=0,totWith=0,totInterest=0;    while (counter