Use Notepad or another text editor to create a text file named Deposits.txt. The
ID: 3649811 • Letter: U
Question
Use Notepad or another text editor to create a text file named Deposits.txt. The file should contain the following numbers, one per line:100.00125.0078.9237.55Next, create a text file named Withdrawals.txt. The file should contain the following numbers, one per line:29.88110.0027.5250.0012.90The 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. The starting balance for the object is 500.00. The program should read the values from the Deposits.txt file and use the objectExplanation / Answer
A deposit account is a current account, savings account, or other type of bank account, at a banking institution that allows money to be deposited and withdrawn by the account holder. These transactions are recorded on the bank's books, and the resulting balance is recorded as a liability for the bank, and represent the amount owed by the bank to the customer. Some banks charge a fee for this service, while others may pay the customer interest on the funds deposited. /** designed by saurav */ import java.io.*; // needed for File and IOException import java.util.Scanner; //imports scanner class import java.text.DecimalFormat; public class DepositWithdraw { public static void main(String[] args)throws IOException { double intRate ; double interestEarned; double amount=0.00; double bal=500.00; // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get the annual interest rate. System.out.print("What is the annual interest rate?"); intRate= keyboard.nextDouble(); // Create a SavingAccount object. SavingAccount SavingAccount1= new SavingAccount(bal,intRate); // Open the Deposits.txt file. File file = new File ("Deposits.txt"); System.out.println("works1"); Scanner inputFile = new Scanner(file); // Get the deposits from the Deposits.txt file while (inFile.hasNext()) while (inputFile.hasNext()); { System.out.println("works1"); //Read numbers double num1 = inputFile.nextDouble(); //Add the numbers amount += num1; } System.out.println("works2"); //Deposit the file input. SavingAccount1.deposit(amount); //Close the Deposits.txt file inputFile.close(); // Open the Withdrawals.txt file. //Open Withdrawal file File file2 = new File("Withdrawal.txt"); Scanner inputFile2 = new Scanner(file2); System.out.println("works3"); // Get the withdrawals from the Withdrawals.txt file while (inFile.hasNext()) while (inputFile2.hasNext()); { //Read numbers double num2 = inputFile2.nextDouble(); //Subtract amount-= num2; } System.out.println("works4"); inputFile2.close(); // Close the Withdrawals.txt file. // Get the balance before adding interest. SavingAccount1.getBalance(); // Add the interest. SavingAccount1.addInterest(); // Calculate the interest earned. SavingAccount1.getLastInterest(); System.out.println("works5"); // Display the interest earned and the balance. System.out.println("Account balance $" + SavingAccount1.getBalance()); System.out.println("Total interest earned $" + SavingAccount1.getLastInterest()); } }//end class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.