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

In Java, please create a program that does the following: Create a program, in J

ID: 3861864 • Letter: I

Question

In Java, please create a program that does the following:

Create a program, in Java, that takes a text file and outputs the results to an output file.

Inside the text file are four records with three fields each which are: loan amount, interest rate, and number of months of the loan (in that order).

Output the data to an output file and also calculate your monthly payment for each record

Contents of the text file:

56750.00 .065 72.00
43675.00 .075 48.00
64950.00 .045 36.00
24799.00 .085 48.00

Example of what the output should look like inside the output text file:

Loan amount s6750,00 Interests 3688.75 Total Faid: 50138 75 Monthly Fayment 839,43 Loan amount E 43675.00 Interesti 32 TS 53 Total Faid: 45850.63 Monthly Fayment E 978, 4 Loan amount E 64950.00 Interesti 2R22.75 Total Faid: 57 72.75 Monthly Payment: Loan Aaroun E 24799.00 Interesti 2107.92 Total Faid: 20906-92 Meathly FammentE S60.56

Explanation / Answer

LoanMontlyPayment.java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Scanner;


public class LoanMontlyPayment {

  
   public static void main(String[] args) throws FileNotFoundException {
       File file = new File("D:\data.txt");
       File output = new File("D:\output.txt");
       PrintWriter pw = new PrintWriter(output);
       if(file.exists()) {
       Scanner scan = new Scanner(file);
       DecimalFormat df = new DecimalFormat("0.00");
      
       while(scan.hasNextLine()){
           double loanAmount = scan.nextDouble();
           double interestRate = scan.nextDouble();
           double numOfMonths = scan.nextDouble();
           double interestAmount = loanAmount * interestRate;
           double totalPaid = loanAmount + interestAmount;
           double montlyPay = totalPaid/numOfMonths;
          
           System.out.println("Loan Amount: "+loanAmount+" Interest: "+df.format(interestAmount)+" Total Paid: "+df.format(totalPaid)+" Monthly Payment: "+df.format(montlyPay));
           pw.write("Loan Amount: "+loanAmount+" Interest: "+df.format(interestAmount)+" Total Paid: "+df.format(totalPaid)+" Monthly Payment: "+df.format(montlyPay)+" ");
          
       }
       pw.flush();
       pw.close();
       scan.close();
       }
       else{
           System.out.println("File does not exist");
       }
   }

}

Output:

Loan Amount: 56750.0 Interest: 3688.75 Total Paid: 60438.75 Monthly Payment: 839.43
Loan Amount: 43675.0 Interest: 3275.62 Total Paid: 46950.62 Monthly Payment: 978.14
Loan Amount: 64950.0 Interest: 2922.75 Total Paid: 67872.75 Monthly Payment: 1885.35
Loan Amount: 24799.0 Interest: 2107.92 Total Paid: 26906.92 Monthly Payment: 560.56

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