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

<p>Use Notepad or another text editor to create a file named deposits.txt. The f

ID: 3627868 • Letter: #

Question

<p>Use Notepad or another text editor to create a file named deposits.txt. The file should contain the following numbers, one per line:<br /><br />100.00<br />124.00<br />78.92<br />37.55<br /><br />Next create a text file named withdrawals.txt. The file should contain the following numbers, one per line.<br /><br />29.88<br />110.00<br />27.52<br />50.00<br />12.90<br /><br />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 Programming Challenge 10. (same book, question 10PC) 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 subtract 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.</p>
<p>&#160;</p>
<p>This is the program from the previous question asked for. &#160;</p>
<p>&#160;</p>
<p>import java.util.*;</p>
<p><span> </span>import java.io.*;</p>
<p><span> </span>import java.text.DecimalFormat;<span> </span></p>
<p><span>&#160;</span><span>&#160;</span>public class BankAccounting {<span> </span></p>
<p><span>&#160;</span><span> </span><br /><span> </span>public static void main(String[] args)</p>
<p>{<span> </span>double inInterest = 0,<span> </span>startingBalance = 0,<span> </span>inDeposit = 0,<span> </span>inWithdrawal = 0;<span> </span></p>
<p>int numMonths = 0;<span> </span></p>
<p>//Gather input data<span> </span>Scanner scan = new Scanner(System.in);</p>
<p><span> </span>System.out.println("What is the annual interest rate?");<span> </span></p>
<p>inInterest = scan.nextDouble();</p>
<p><span> </span>System.out.println("What is the starting balance?");<span> </span></p>
<p>startingBalance = scan.nextDouble();</p>
<p><span> </span>System.out.println("How many months have passed since the account was opened?");</p>
<p><span> </span>numMonths = scan.nextInt();</p>
<p><span> </span>//create new account object<span> </span>SavingsAccount myAccount = new SavingsAccount(startingBalance);<span> </span></p>
<p>//iterate through months asking for deposits and withdrawals<span> </span>for (int i = 0; i &lt; numMonths; i++)<span> </span></p>
<p>{<span> </span>System.out.println("What was the months deposit total?");</p>
<p><span> </span>inDeposit = scan.nextDouble();<span> </span></p>
<p>System.out.println("What is the months withdrawal total?");<span> </span></p>
<p>inWithdrawal = scan.nextDouble();</p>
<p><span> </span>myAccount.Deposit(inDeposit);<span> </span></p>
<p>myAccount.Withdrawal(inWithdrawal);<span> </span></p>
<p>myAccount.Interest(inInterest/12.00);<span> </span>}<span> </span></p>
<p>//printing summary report<span> </span>myAccount.PrintSummary();</p>
<p><span> </span>}<span> </span>}<span> </span></p>
<p>class SavingsAccount<span> </span>{<span> </span></p>
<p>double balance,<span> </span>interestEarned = 0,<span> </span>totalDeposits = 0,<span> </span>totalWithdrawals = 0;<span> </span></p>
<p>//constructor that accepts a double to assign as starting balance<span> </span>public SavingsAccount(double startAmount)<span> </span>{<span> </span></p>
<p>balance = startAmount;</p>
<p><span> </span>}<span> </span></p>
<p>//Deposit method that adds to balance and total deposits<span> </span>public void Deposit(double amount)<span> </span></p>
<p>{</p>
<p><span> </span>balance += amount;<span> </span>totalDeposits += amount;</p>
<p><span> </span>}<span> </span></p>
<p>//Withdrawal method that subtracts from balance and adds to total&#160;Withdrawals<span> </span></p>
<p>public void Withdrawal(double amount)<span> </span>{</p>
<p>balance -= amount;<span> </span>totalWithdrawals += amount;</p>
<p><span> </span>}</p>
<p><span> </span>//Interest method that calculates interest<span> </span>public void Interest(double rate)<span> </span>{<span> </span>double tempInterest = 0;<span> </span>tempInterest = rate * balance;<span> </span>interestEarned += tempInterest;<span> </span>balance += tempInterest;<span> </span>}<span> </span>//Print method that prints out summary page<span> </span>public void PrintSummary()<span> </span>{<span> </span>DecimalFormat df = new DecimalFormat("#.00");<br /><span> </span>System.out.println(" Balance : " + df.format(balance));<span> </span>System.out.println(" Deposits : " + df.format(totalDeposits));<span> </span>System.out.println(" Withdrawals : " + df.format(totalWithdrawals));<span> </span>System.out.println("Interest Earned : " + df.format(interestEarned));<span> </span>}<span> </span>}<br /><br /><br /></p>

Explanation / Answer

please rate - thanks

import java.text.DecimalFormat;
class SavingsAccount
{
double balance,
interestEarned = 0,
totalDeposits = 0,
totalWithdrawals = 0;
//constructor that accepts a double to assign as starting balance
public SavingsAccount(double startAmount)
{
balance = startAmount;
}
//Deposit method that adds to balance and total deposits
public void Deposit(double amount)
{
balance += amount;
totalDeposits += amount;
}
//Withdrawal method that subtracts from balance and adds to total Withdrawals
public void Withdrawal(double amount)
{
balance -= amount;
totalWithdrawals += amount;
}
//Interest method that calculates interest
public void Interest(double rate)
{
double tempInterest = 0;
tempInterest = rate * balance;
interestEarned += tempInterest;
balance += tempInterest;
}
//Print method that prints out summary page
public void PrintSummary()
{
DecimalFormat df = new DecimalFormat("#.00");

System.out.println(" Balance : " + df.format(balance));
System.out.println(" Deposits : " + df.format(totalDeposits));
System.out.println(" Withdrawals : " + df.format(totalWithdrawals));
System.out.println("Interest Earned : " + df.format(interestEarned));
}
}

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


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


interest=5;
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.Withdrawal(withdraw);
      }
in2.close();

account.Interest(interest);
account.PrintSummary();


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote