Question

In: Computer Science

Please do the following in JAVA. Deposit and Withdrawal Files Use Notepad or another text editor...

Please do the following in JAVA.

Deposit and Withdrawal Files 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.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 Programming Challenge 12. 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( Use 10% as the interest rate ), and then display the ending balance and the total interest earned.

Solutions

Expert Solution

Note :

We have to paste the input file in the project folder so that our program can able to detect.

If we didnt placed the input file in the project folder we will get FileNotFoundException.

We have to paste the input file in the project folder so that our program can able to detect.
Could you plz go through this code and let me know if u need any changes in this.Thank You

=================================

// Deposits.txt (Input file)

100.00
125.00
78.92
37.55

===================================

// Withdrawls.txt (Input file)

29.88
110.00
27.52
50.00
12.90

===================================

// SavingsAccount.java

public class SavingsAccount {
   private double interestrate;
   private double balance;

   /**
   * @param balance
   */
   public SavingsAccount(double balance) {
       this.balance = balance;
       this.interestrate = 0.10;
   }

   /**
   * @return the balance
   */
   public double getBalance() {
       return balance;
   }

   public void withdraw(double amt) {
       if (balance - amt >= 0) {
           balance -= amt;
       }
   }

   public void deposit(double amt) {
       if (amt > 0) {
           this.balance += amt;
       }
   }

   public double calculateMonthlyInterest() {
       double interestAmt = (interestrate) * balance;
       this.balance += interestAmt;
       return interestAmt;
   }

}

========================================

========================================

// Test.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Test {

   public static void main(String[] args) throws FileNotFoundException {
       Scanner sc = null;
       double amt;
       SavingsAccount sa = new SavingsAccount(500);
       sc = new Scanner(new File("Deposits.txt"));

       while (sc.hasNext()) {
           amt = sc.nextDouble();
           sa.deposit(amt);
       }

       sc.close();

       sc = new Scanner(new File("Withdrawls.txt"));

       while (sc.hasNext()) {
           amt = sc.nextDouble();
           sa.withdraw(amt);
       }

       sc.close();

       System.out.println("Monthly Interest is :$"+ sa.calculateMonthlyInterest());
       System.out.printf("Ending balance is :$%.2f" , sa.getBalance());

   }

}

========================================

========================================

Output:

============================== Thank You


Related Solutions

In JAVA : There are two text files with the following information stored in them: The...
In JAVA : There are two text files with the following information stored in them: The instructor.txt file where each line stores the id, name and affiliated department of an instructor separated by a comma The department.txt file where each line stores the name, location and budget of the department separated by a comma You need to write a Java program that reads these text files and provides user with the following menu: 1. Enter the instructor ID and I...
Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt)...
Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
you can use either vim or nano as text editor Implement the following code in ARM...
you can use either vim or nano as text editor Implement the following code in ARM on Raspberry Pi, compile and run. g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note: answer should be calculated not hardcoded
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
Use the Table button in the Rich-Text Editor to provide an adjacency matrix for a simple...
Use the Table button in the Rich-Text Editor to provide an adjacency matrix for a simple graph that meets the following requirements: 1) has 5 vertices 2) is maximal planar
The vi text editor can be a bit challenging to use at first, but once you...
The vi text editor can be a bit challenging to use at first, but once you have familiarized yourself with how it works you will find it an efficient way to create and edit text files in Linux, and UNIX as well. The key thing to remember is that vi has two operational modes: insert mode and command mode. In insert mode, everything you type is entered into your file. You can use the backspace, delete and the arrow keys....
Use Vi text editor or ATOM to create a bash script file. Use the file name...
Use Vi text editor or ATOM to create a bash script file. Use the file name ayaan.sh. The script when ran it will execute the following commands all at once as script. Test your script file make sure it works. Here is the list of actions the script will do: It will create the following directory structure data2/new2/mondaynews off your home directory. inside the mondaynews, create 4 files sports.txt, baseball.txt, file1.txt and file2.txt. Make sure file1.txt and file2.txt are hidden...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep...
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
This assignment involves the use of text files, lists, and exception handling and is a continuation...
This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>> Enter gender (boy/girl): boy...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT