My Credit Card Company has a file that called BeginningBalan
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
Solution
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\\tBeg. Bal.\\tFinance Charge\\tPurchases\\tPayments\\tEnding Bal.\");
while(in.hasNext()){
cid = in.nextInt();
beginBal = in.nextDouble();
purchases = in.nextDouble();
payments = in.nextDouble();
charges = beginBal * .01;
System.out.println(cid + \"\\t\" + beginBal + \"\\t\\t\" + charges + \"\\t\\t\" + purchases + \"\\t\\t\" + payments + \"\\t\\t\" + (beginBal + purchases + charges - payments));
out.write(cid + \"\ \" + (beginBal + purchases + charges - payments) + \"\ \");
}
out.close();
}
}

