package msg;
import java.io.*;
import java.util.*;
class Mortgage extends Asset
{
//
// Instance variables
//
private String mortgageeName; // names of mortgagees
private float price; // price paid for mortgaged property
private String dateMortgageIssued; // date mortgage was issued
private float currentWeeklyIncome; // weekly income of mortgagees
private String weeklyIncomeUpdated; // date weekly income updated
private float annualPropertyTax; // annual property tax
private float annualInsurancePremium; // annual insurance premium
private float mortgageBalance; // mortgage balance
static final int NUMBER_OF_MORTGAGE_PAYMENTS = 1560;
static final float MAXIMUM_PERC_OF_INCOME = (float) 0.28;
static final float WEEKS_IN_YEAR = (float) 52.0;
static final float INTEREST_RATE = (float) 0.04;
// getter-setter methods for Mortgage
public String getMortgageeName () { return mortgageeName; }
public void setMortgageeName (String n) { mortgageeName = n; }
public float getPrice () { return price; }
public void setPrice (float p) { price = p; }
public String getDateMortgageIssued () { return dateMortgageIssued; }
public void setDateMortgageIssued (String d) { dateMortgageIssued = d; }
public float getCurrentWeeklyIncome () { return currentWeeklyIncome; }
public void setCurrentWeeklyIncome (float c) { currentWeeklyIncome = c; }
public String getWeeklyIncomeUpdated () { return weeklyIncomeUpdated; }
public void setWeeklyIncomeUpdated (String w) { weeklyIncomeUpdated = w; }
public float getAnnualPropertyTax () { return annualPropertyTax; }
public void setAnnualPropertyTax (float p) { annualPropertyTax = p; }
public float getAnnualInsurancePremium () { return annualInsurancePremium; }
public void setAnnualInsurancePremium (float a) { annualInsurancePremium = a; }
public float getMortgageBalance () { return mortgageBalance; }
public void setMortgageBalance (float m) { mortgageBalance = m; }
//
// Instance methods
//
public float totalWeeklyNetPayments ()
//
// Computes the net total weekly payments made by the mortgagees, that is,
// the expected total weekly mortgage amount less the expected total weekly grants.
//
{
try
{
File mortgageFile = new File ("mortgage.dat"); // file of mortgage records
float expectedTotalWeeklyMortgages = (float) 0.0; // expected total weekly mortgages
float expectedTotalWeeklyGrants = (float) 0.0; // expected total weekly grants
float capitalRepayment = (float) 0.0; // capital repayment
float interestPayment = (float) 0.0; // interest payment
float escrowPayment = (float) 0.0; // escrow payment
float tempMortgage = (float) 0.0; // temporary mortgage payment
float maximumPermittedMortgagePayment = (float) 0.0; // maximum a family is allowed to pay
if (mortgageFile.exists ())
{
RandomAccessFile inFile = new RandomAccessFile (mortgageFile, "r");
while (inFile.getFilePointer () != inFile.length ())
{
read (inFile);
capitalRepayment = price / NUMBER_OF_MORTGAGE_PAYMENTS;
interestPayment = mortgageBalance * INTEREST_RATE / WEEKS_IN_YEAR ;
escrowPayment = (annualPropertyTax + annualInsurancePremium) / WEEKS_IN_YEAR;
tempMortgage = capitalRepayment + interestPayment + escrowPayment;
expectedTotalWeeklyMortgages += tempMortgage;
maximumPermittedMortgagePayment = currentWeeklyIncome * MAXIMUM_PERC_OF_INCOME;
if (tempMortgage > maximumPermittedMortgagePayment)
expectedTotalWeeklyGrants += tempMortgage - maximumPermittedMortgagePayment;
}
inFile.close ();
} // if
return (expectedTotalWeeklyMortgages - expectedTotalWeeklyGrants);
}
catch (Exception e)
{
System.out.println ("***** Error: Mortgage.totalWeeklyNetPayments () *****");
System.out.println ("\t" + e);
return ( (float) 0.0);
}
} // totalWeeklyNetPayments
//----------------------------------------------------------------------------------------------------------------------------------------------------
public boolean find (String findMortgageID)
//
// find locates a given mortgage record if it exists.
// Returns true if the mortgage is located, otherwise false.
//
{
try
{
File mortgageFile = new File ("mortgage.dat"); // file of mortgage records
boolean found = false; // result of comparison
if (mortgageFile.exists ())
{
RandomAccessFile inFile = new RandomAccessFile (mortgageFile, "r");
while (!found && (inFile.getFilePointer () != inFile.length ()))
{
read (inFile);
if (assetNumber.compareTo (findMortgageID) == 0) found = true;
}
inFile.close ();
}
return found;
}
catch (Exception e)
{
System.out.println ("***** Error: Mortgage.find () *****");
System.out.println ("\t" + e);
return false;
}
} // find
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void read (RandomAccessFile fileName)
//
// reads a mortgage record from fileName.
// Assumes that the existence of fileName has already been established.
//
{
try
{
String inputString = new String (); // for storing mortgage record
int i = 0; // position within string
inputString = fileName.readLine ();
StringBuffer input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
assetNumber = input.toString ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
mortgageeName = input.toString ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
Float tempFloat = new Float (input.toString ());
price = tempFloat.floatValue ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
dateMortgageIssued = input.toString ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
tempFloat = new Float (input.toString ());
currentWeeklyIncome = tempFloat.floatValue ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
weeklyIncomeUpdated = input.toString ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
tempFloat = new Float (input.toString ());
annualPropertyTax = tempFloat.floatValue ();
i++;
input = new StringBuffer ();
while (inputString.charAt (i) != '|')
{
input.append (inputString.charAt (i));
i++;
}
tempFloat = new Float (input.toString ());
annualInsurancePremium = tempFloat.floatValue ();
i++;
input = new StringBuffer ();
while (i < inputString.length ())
{
input.append (inputString.charAt (i));
i++;
}
tempFloat = new Float (input.toString ());
mortgageBalance = tempFloat.floatValue ();
i++;
}
catch (Exception e)
{
System.out.println ("***** Error: Mortgage.read () *****");
System.out.println ("\t" + e);
}
} // read
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void write (RandomAccessFile fileName)
//
// writes a mortgage record to specified file.
//
{
try
{
fileName.writeBytes (assetNumber + "|" + mortgageeName + "|");
fileName.writeBytes (price + "|" + dateMortgageIssued.toString () + "|");
fileName.writeBytes (currentWeeklyIncome + "|" + weeklyIncomeUpdated.toString () +
银行借贷系统(Java编程)
3星 · 超过75%的资源 需积分: 41 162 浏览量
2009-11-14
22:30:26
上传
评论 5
收藏 15KB ZIP 举报
wwzhang2013
- 粉丝: 0
- 资源: 2