MacroGuru
08-22-2005, 04:17 PM
Can anyone take a look at my program and tell me where the fault is at?
I am supposed to generate Amortization for 3 different mortgages, and I am getting 2 errors I cannot figure out.
Thanks
/*
*POS/406
*Mortgage Application
*By Dennis Thomas
*/
import java.text.*;
import java.io.*;
public class Mortgage{
public static void main(String[] arguments){
//Define Mortgage Array
Mortgage[] arrMortgages = new mortgages[3];
//Define the objects in the array
arrMortgage[0] = new Mortgage(200,000, 30, .0575);
arrMortgage[1] = new Mortgage(200,000, 7, .0535);
arrMortgage[2] = new Mortgage(200,000, 15, .055);
double dPrincipal;
int iTerm;
double dRate;
double dnumPayments;
double dmonthlyPayment;
int iPeriods = 12;
// Loop rest of program through all 3 mortgages
for (int x=0; x<3; x++) {
// Display Loan Info before displaying Amoritization Table
DisplayInfo(mortgages[x], x);
Mortgage.pause();
// Display Amoritization Table for each loan
mortgages[x].DisplayAmoritization();
Mortgage.pause();
public Mortgage(double dPrincipal, int iTerm, double dRate){
dnumPayments = iTerm*iPeriods
dmonthlyPayment = this.MonthlyPayment
}
public void DisplayInfo(Mortgage m, int iNum){
//Display prefigured information to the end user
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Mortgage Amount is" + nf.format(dPrincipal));
System.out.println("\t\n Your Yearly Interest Rate is " + dRate);
System.out.println("\t\n Your Term years are " + iTerm);
m.MonthlyRate();
m.TotalMonths();
m.MonthlyPayment();
}
public double MonthlyRate(){
dMonthRate = dRate/(12 * 100);//figure out the Monthly Rate
System.out.println("\t\n Your Monthly Rate is " + dMonthRate);
}
public int TotalMonths(){
iMonthsTotal = iTerm*12;//figure out the total months of the loan
System.out.println("\t\n Your total months on the loan are " + iMonthsTotal);
}
public double MonthlyPayment(){
dmonthlyPayment = iAmount * ( (dMonthRate * Math.pow((1+dMonthRate),iMonthsTotal)) / (Math.pow((1+dMonthRate),iMonthsTotal) - 1) );//figure out the monthly payment
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Monthly Payment is " + nf.format(dPayment));
}
public void DisplayAmoritization(){
double dCurrentMonthlyInterest;
double dPaymentAmount;
double dPaymentBalance;
double dp = dPrinciple; // changeable principle variable for this function
double dMI = dRate/iPeriods; // monthly interest = interest/12
System.out.println("\t\tBalance\t\tMonthly Payment\t\tAmt Principle\t\tAmt Interest");
for (int x = 0; x < dnumPayments; x++) {
//pause every 15 lines
double numLines = 15.00;
int dummy = (int)x/15;
if (((x/numLines) == (double)dummy)&&(dummy != 0)) {
Mortgage.pause();
}
// figuring and outputting amortization stuff
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
dCurrentMonthlyInterest = dp * dMI;
dPaymentAount = dmonthlyPayment - dCurrentMonthlyInterest;
dPaymentBalance = dp - dPaymentAmount;
System.out.println((x+1) + "\t\t" + nf.format(dp) + "\t\t" + nf.format(dmonthlyPayment) + "\t\t\t" + nf.format(dPaymentAmount) + "\t\t\t" + nf.format(dCurrentMonthlyInterest));
dp = dPaymentBalance;
}
}
}
}
}
I am supposed to generate Amortization for 3 different mortgages, and I am getting 2 errors I cannot figure out.
Thanks
/*
*POS/406
*Mortgage Application
*By Dennis Thomas
*/
import java.text.*;
import java.io.*;
public class Mortgage{
public static void main(String[] arguments){
//Define Mortgage Array
Mortgage[] arrMortgages = new mortgages[3];
//Define the objects in the array
arrMortgage[0] = new Mortgage(200,000, 30, .0575);
arrMortgage[1] = new Mortgage(200,000, 7, .0535);
arrMortgage[2] = new Mortgage(200,000, 15, .055);
double dPrincipal;
int iTerm;
double dRate;
double dnumPayments;
double dmonthlyPayment;
int iPeriods = 12;
// Loop rest of program through all 3 mortgages
for (int x=0; x<3; x++) {
// Display Loan Info before displaying Amoritization Table
DisplayInfo(mortgages[x], x);
Mortgage.pause();
// Display Amoritization Table for each loan
mortgages[x].DisplayAmoritization();
Mortgage.pause();
public Mortgage(double dPrincipal, int iTerm, double dRate){
dnumPayments = iTerm*iPeriods
dmonthlyPayment = this.MonthlyPayment
}
public void DisplayInfo(Mortgage m, int iNum){
//Display prefigured information to the end user
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Mortgage Amount is" + nf.format(dPrincipal));
System.out.println("\t\n Your Yearly Interest Rate is " + dRate);
System.out.println("\t\n Your Term years are " + iTerm);
m.MonthlyRate();
m.TotalMonths();
m.MonthlyPayment();
}
public double MonthlyRate(){
dMonthRate = dRate/(12 * 100);//figure out the Monthly Rate
System.out.println("\t\n Your Monthly Rate is " + dMonthRate);
}
public int TotalMonths(){
iMonthsTotal = iTerm*12;//figure out the total months of the loan
System.out.println("\t\n Your total months on the loan are " + iMonthsTotal);
}
public double MonthlyPayment(){
dmonthlyPayment = iAmount * ( (dMonthRate * Math.pow((1+dMonthRate),iMonthsTotal)) / (Math.pow((1+dMonthRate),iMonthsTotal) - 1) );//figure out the monthly payment
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Monthly Payment is " + nf.format(dPayment));
}
public void DisplayAmoritization(){
double dCurrentMonthlyInterest;
double dPaymentAmount;
double dPaymentBalance;
double dp = dPrinciple; // changeable principle variable for this function
double dMI = dRate/iPeriods; // monthly interest = interest/12
System.out.println("\t\tBalance\t\tMonthly Payment\t\tAmt Principle\t\tAmt Interest");
for (int x = 0; x < dnumPayments; x++) {
//pause every 15 lines
double numLines = 15.00;
int dummy = (int)x/15;
if (((x/numLines) == (double)dummy)&&(dummy != 0)) {
Mortgage.pause();
}
// figuring and outputting amortization stuff
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
dCurrentMonthlyInterest = dp * dMI;
dPaymentAount = dmonthlyPayment - dCurrentMonthlyInterest;
dPaymentBalance = dp - dPaymentAmount;
System.out.println((x+1) + "\t\t" + nf.format(dp) + "\t\t" + nf.format(dmonthlyPayment) + "\t\t\t" + nf.format(dPaymentAmount) + "\t\t\t" + nf.format(dCurrentMonthlyInterest));
dp = dPaymentBalance;
}
}
}
}
}