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.
Solution
code.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
public class code {
private static final String FILENAME = \"NewBalance.dat\";
public static void main(String[] args) {
try
{
File file = new File(\"BeginningBalance.dat\");
;
BufferedWriter bw = null;
FileWriter fw = null;
fw = new FileWriter(FILENAME);
bw = new BufferedWriter(fw);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while(true)
{
String line;
line = bufferedReader.readLine();
if(line == null)
{
break;
}
String[] parts = line.split(\" \");
String ss = parts[0];
String vv = parts[1];
int Acc_no = Integer.parseInt(vv);
line = bufferedReader.readLine();
parts = line.split(\" \");
ss = parts[0];
vv = parts[1];
double Start_bal = Float.valueOf(vv);
line = bufferedReader.readLine();
parts = line.split(\" \");
ss = parts[0];
vv = parts[1];
double purchase = Double.parseDouble(vv);
line = bufferedReader.readLine();
parts = line.split(\" \");
ss = parts[0];
vv = parts[1];
double payment = Double.parseDouble(vv);
double charges = Start_bal/100;
double new_bal = Start_bal - purchase - payment -charges;
fw.write(Integer.toString(Acc_no));
fw.write(\" \");
fw.write(Double.toString(new_bal));
fw.write(\"\ \");
}
fileReader.close();
fw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
BeginningBalance.dat
Customernumber 1111
Beginning_bal 1000
Purchases 200
Payments 500
Customernumber 2222
Beginning_bal 1000
Purchases 200
Payments 500
Customernumber 3333
Beginning_bal 2000
Purchases 400
Payments 1000
NewBalance.dat
1111 290.0
2222 290.0
3333 580.0

