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

My Credit Card Company has a file that called “BeginningBalance.dat” which conta

ID: 3774917 • Letter: M

Question

My Credit Card Company has a file that called “BeginningBalance.dat” which contains the following information: • Customer number->integer • Beginning Balance->double • Purchases->double • Payments->double  

The company charges 1% of the beginning balance for finance charges. Write a Java program that does the following:   • Read in the file, calculates the finance charge per customer • Display all information to the monitor including finance charge and outstanding balance • Creates an output file called “NewBalance.dat” that contains customer number and new balance.

E. Example of input and output

BeginningBalance.dat should look like this:

111

100.00

200.00

50.00

222

200.00

300.00

100.00

The display should look like this:

Cust No    Beg. Bal.        Finance Charge       Purchases      Payments       Ending Bal.

111           100.00               1.00                        200.00             50.00                251.00

222          200.00              2.00                        300.00             100.00              402.00

Totals       300.00               3.00                        500.00             150.00               653.00

NewBalance.dat should look like this:

111

251.00

222

402.00

Explanation / Answer

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

public class Main{
   public static void main(String args[]) throws FileNotFoundException{
       File input;
       input = new File("BeginningBalance.dat");
       Scanner in;
       in = new Scanner(input);
       PrintWriter out = new PrintWriter(new File("NewBalance.dat"));
       int cid;
       double beginBal, purchases, payments, charges;
       System.out.println("Cust No Beg. Bal. Finance Charge Purchases Payments Ending Bal.");
       while(in.hasNext()){
           cid = in.nextInt();
           beginBal = in.nextDouble();
           purchases = in.nextDouble();
           payments = in.nextDouble();
           charges = beginBal * .01;
           System.out.println(cid + " " + beginBal + " " + charges + " " + purchases + " " + payments + " " + (beginBal + purchases + charges - payments));
           out.write(cid + " " + (beginBal + purchases + charges - payments) + " ");
       }
       out.close();
   }
}

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