I am have a real hard time with this program i have to write. The program has to
Read in from the file
Print out AND write to a file a table that contains the following:
Property Taxes Net price
Calculations:
i have no clue how to separate the data and do separate calculations!! A sample data file looks like this...
Hopkins 250000 223000 209000
Smith 305699 299999 297500
Forrest 124999 124999 53250
Fitch 214999 202500 200000
There is no way i can read the data then do the calculations and then write the new data to a new file, please help!
try {
float netTotal = 0;
String thisLine = null;
FileOutputStream out = new FileOutputStream("out.txt");
BufferedReader br = new BufferedReader(new FileReader("inputFile.txt"));
while ((thisLine = br.readLine()) != null) { // while loop begins here
String[] parts = thisLine.split("[\\t\\n\\r ]+");
int askingPrice = Integer.parseInt(parts[1]);
int salePrice = Integer.parseInt(parts[2]);
int amountOwed = Integer.parseInt(parts[3]);
float commission = salePrice * 0.06;
float tax = salePrice * 0.105;
float netPrice = askingPrice - amountOwed - commission;
netTotal += netPrice;
out.write((parts[0] + "\t").getBytes()); //name
out.write((askingPrice + "\t").getBytes()); //asking price
out.write((amountOwed + "\t").getBytes()); //mortgage amount
out.write((salePrice + "\t").getBytes()); //selling price
out.write((commission + "\t").getBytes()); //realtor commission
out.write((tax + "\t").getBytes()); //sales tax
out.write((netPrice + "\t\n").getBytes()); //net price
}
out.close();
br.close();
System.out.println("Net profit/loss: " + netTotal);
}
catch (Exception e) {
e.printStackTrace();
}