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...
In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name "Test" and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named "361" 5-Copy file "Test" to...
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...
Modify the attached files to do the following in java: 1) Add all necessary Getters and...
Modify the attached files to do the following in java: 1) Add all necessary Getters and Setters to the Class file. 2) Add code to compare two instances of the class to see which one comes before the other one based on the zipcode. //Address1.java public class Address {    // attributes    private String street, aptNum, city, state;    private int zip;    // constructors    public Address(String street, String aptNum, String city, String state, int zip)    {...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT