Question

In: Computer Science

(Java)// Slightly different problem from the others that use the same input files, it has been...

(Java)// Slightly different problem from the others that use the same input files, it has been adapted from a practice problem//

// Also if you can keep the code as simple as possible, try to avoid any advanced techniques, so that I can easily understand what is happening in case I decide to use this for future reference (which most likely I am) that'd be super appreciated//

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:

///////////// Deposits.txt /////////////

100.00

125.00

78.92

37.55

/////////////////////////////////////////////

Next, create a text file named Withdrawals.txt. The file should contain the following numbers, one per line:

///////////// Withdrawals.txt /////////////

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. The starting balance on the account is $500.00. The program should read the values from the Deposits.txt file and add them to the starting balance of the account. The program should read the values from the Withdrawals.txt file and subtract them from the account balance. Display the new balance after each deposit and withdrawal so that you can see the change to the account balance in the output, and display the total interest earned (The interest is 10%). // This is an adapted version of a practice problem, so if the interest part doesn't make sense in this scenairo please feel free to omit it.//

Solutions

Expert Solution

Program Screenshot :

Program code:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;

public class ReadFiles {
   private static DecimalFormat df = new DecimalFormat("0.00");

   public static void main(String[] args) throws IOException {
       // Read text file Deposits.txt  
       BufferedReader deposit = new BufferedReader(new FileReader("Deposits.txt"));
       // Read text file Withdrawals.txt
       BufferedReader withDraw = new BufferedReader(new FileReader("Withdrawals.txt"));
       //   The starting balance on the account is 500.00
       double accoutBalence = 500.00;
       double withdrwalBalance = 0.0;
       // First line of Deposits.txt      
       String dep = deposit.readLine();
       // First line of Withdrawals.txt
String with = withDraw.readLine();
// Read both lines till reaches to null
while(dep != null || with != null) {
   try {
       // read the values from the Deposits.txt file and add them to the starting balance of the account.        
       accoutBalence = accoutBalence + Double.parseDouble(dep);
       // Display the new balance after each deposit
   System.out.println("After each deposit : " + df.format(accoutBalence));
   // read the values from the Withdrawals.txt file and subtract them from the account balance    
   accoutBalence = accoutBalence - Double.parseDouble(with);
   // Display the new balance after each deposit and withdrawal
   System.out.println("After each withdrawl : " + df.format(accoutBalence));
   withdrwalBalance = withdrwalBalance + Double.parseDouble(with);
   // Read next lines in the text files
   dep = deposit.readLine();
   with = withDraw.readLine();
      
   }catch(NullPointerException e) {}
}
deposit.close();
withDraw.close();
  
}

}


Sample output:


Related Solutions

In C++, develop a menu program which reads in data from 4 different input files -...
In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions...
JAVA There is a folder named Recursive folder at the same location as these below files,...
JAVA There is a folder named Recursive folder at the same location as these below files, which contains files and folders. I have read the data of the Recursive folder and stored in a variable. Now they are required to be encrypted and decrypted. You may copy past the files to three different files and see the output. I am confused on how to write code for encrypt() and decrypt() The names of files and folders are stored in one...
#72: Note: On this problem, some of your answers might be slightly different from Moodle's because...
#72: Note: On this problem, some of your answers might be slightly different from Moodle's because of rounding error. The table below gives the gold medal times for every other Summer Olympics for the women's 100-meter freestyle (swimming). Year Time (seconds) 1912 82.2 1924 72.4 1932 66.8 1952 66.8 1960 61.2 1968 60.0 1976 55.65 1984 55.92 1992 54.64 2000 53.8 2008 53.1 a. Decide which variable should be the independent variable and which should be the dependent variable. Independent...
Write a JAVA program that compares two strings input to see if they are the same?
Write a JAVA program that compares two strings input to see if they are the same?
The algorithm is basically as follows. The notation is slightly different from that in the website...
The algorithm is basically as follows. The notation is slightly different from that in the website you were given, but there is no difference in the method. Given the initial value problem dy/dx=f(x,y),y(a)= y_0 Euler’s Method with step size h consists in applying the iterative formula y_(n+1)= y_n+h∙f(x_n,y_n ),n≥0 To compute successive approximations y_1,y_2,y_3,⋯ to the (true) values 〖y(x〗_1),〖y(x〗_2),〖y(x〗_3),⋯ of the exact solution y=y(x) at the points x_1,x_2,x_3,⋯, respectively. In plain English: You want to approximate the value of dy/dx...
The algorithm is basically as follows. The notation is slightly different from that in the website...
The algorithm is basically as follows. The notation is slightly different from that in the website you were given, but there is no difference in the method. Given the initial value problem dy/dx=f(x,y),y(a)= y_0 Euler’s Method with step size h consists in applying the iterative formula y_(n+1)= y_n+h∙f(x_n,y_n ),n≥0 To compute successive approximations y_1,y_2,y_3,⋯ to the (true) values 〖y(x〗_1),〖y(x〗_2),〖y(x〗_3),⋯ of the exact solution y=y(x) at the points x_1,x_2,x_3,⋯, respectively. In plain English: You want to approximate the value of dy/dx...
How is the problem with personal care products different from the problem with pharmaceuticals? Use the...
How is the problem with personal care products different from the problem with pharmaceuticals? Use the following terms to guide your answer. Exposure: Safety: Labeling:
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the integers SORTED USING RADIX SORT. You may assume all your input consists of integers <=9999. Your main program will input the integers and put them into a QUEUE. It will then pass this queue to a method called radixSort which will sort the numbers in the queue, passing the sorted queue back to main. The main program will then call another method to print...
Consider the problem of carbon dioxide emissions. We will abstract away from the problem slightly, assuming...
Consider the problem of carbon dioxide emissions. We will abstract away from the problem slightly, assuming there are pollutions and consumer in two regions, the OECD (O) and the rest of the world (R). Suppose the marginal cost of controlling CO2 emissions is $10 per ton of emissions. Let the marginal willingness to pay for pollution reduction be 13-Q for region O and 12-2Q for region R, where Q is the amount of pollution reduction. The United Nations is considering...
5. (a) If input prices stay the same, a firm has the same output target, and...
5. (a) If input prices stay the same, a firm has the same output target, and there is neutral technological change, how does this affect the quantity of input the firm uses to produce the target output at minimum cost? (b) How does this affect the factor intensity of the firm’s choice? (c) Give a real example from history – any example -- of non-neutral technical change and tell me whether it was capital- or labor-saving.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT