public class Lab9FileInterest
{
public static void main(String[] args)throws java.io.IOException
{
double Prin,mp,p,i,t;
double Inter = 0.07;
int Time;
FileWriter fw = new FileWriter("Mortgage Table.txt");
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.print(" Wachovia");
pw.print(" Manager: Linkinkampf19 ");
pw.print(" Principle Interest Time Payment");
for (Prin = 50000; Prin <= 100000; Prin++)
{
for(Time = 15; Time <= 30; Time++)
{
mp = computeMortgage(Prin, Inter, Time);
DecimalFormat num = new DecimalFormat("$,###.00");
if (Prin < 100000)
pw.println(" " + num.format(Prin) + " " + Inter + " " + Time + " " + num.format(mp));
else
pw.println(" " + num.format(Prin) + " " + Inter + " " + Time + " " + num.format(mp));
}
}
pw.close();
}
public static double computeMortgage(double Prin, double Inter, double Time) {
double mp; //mp is mortgage payment
DecimalFormat num = new DecimalFormat("$,###.00");
mp = (Prin*(Inter/12)/(1-Math.pow((1)/(1+(Inter/12)),(Time*12))));
return mp;
}
}