Use notepad or another text editor to create a text file named deposits.txt. The
ID: 3625026 • Letter: U
Question
Use notepad or another text editor to create a text file named deposits.txt. The file should contain the followingnumbers, 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 numbers, one per line:
29.88
110.00
27.52
50.00
12.90
The numbers in the deposits.txt file are the amounts of deposits that were made to a savings account during the 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 SavingsAccount class that you wrote in the programming challenge 10. The starting balance for the object is 500.00. The program should read the values from the Deposits.txt file and use the object's method to add them to the account balance. The program should read the values from the Withdrawals.txt file and use the object's method to substract them from the account balance. The program should call the class method to calculate the monthly interest, and then display the ending balance and the total interest earned.
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() );
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.