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

use notepad or another text editor to create a text file named deposits.txt. the

ID: 3628133 • Letter: U

Question

use notepad or another text editor to create a text file named deposits.txt. the file should contain the following number, one per line

100.00
124.00
78.92
37.55

next create a text file named withdrawals.txt. the file should contain the following number one per line

29.88
110.00
27.52
50.00
12.90

the number in the deposits.txt file are the amounts of deposits that were made to saving account during month. and the numbers in the withdrawals.txt file are the amounts of withdrawals that were made during the month. write a program that creates an instance of the saving account class that you wrote in programming challenge 10(saving account class). the starting balance for the object is 500.00.

the program should read the values from the deposit.txt file and use the objects method to add them to the account balance.

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class SavingAccountTest2
{public static void main(String[] args) throws FileNotFoundException
{double balance,interest,withdraw,deposit;
int months,i;
SavingAccount account = new SavingAccount();

balance=500;
account.Balance(balance);
interest=5;
account.setInterestRate(interest);
Scanner in=new Scanner(new File("deposits.txt"));
while(in.hasNextDouble())
{deposit=in.nextDouble();
account.deposit(deposit);
      }
in.close();
Scanner in2=new Scanner(new File("withdrawals.txt"));
while(in2.hasNextDouble())
{withdraw=in2.nextDouble();
account.withdraw(withdraw);
      }
in2.close();

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;
}
}