Hello everybody! I am a new java programmer student and I am in desperate need of help with my java program for a mortgage amortization. I have included my code as well. Can some one tell me what I am doing wrong. I compile the code and I have received numerous errors. Please help!
// java package
import java.text.DecimalFormat;
import java.util.Scanner;
// This will calculate a 30yr mortgage monthly payment
public class DavisMortgageCal2
{
public static void main(String[] args)
{
// declare variables
double intrest,payment;
int ammount,term;
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
intrest=.0575;
ammount=200000;
term=30;
payment=(ammount*((intrest/12)/(1-Math.pow((1+(intrest/12)),-(term*12)))));
// Calculator outputs
System.out.println("Principal="+ammount);
System.out.println("intrest rate="+intrest*100);
System.out.println("Years="+term);
System.out.println("Number of payments="+term*12);
System.out.print("Monthly Payment=");
System.out.println(decimalPlaces.format(payment));
Scanner input = new Scanner(System.in);
System.out.print("Please enter the original loan amount $ (-1 to end the program): ");
ending_balance = input.nextDouble();
System.out.print("Enter the interest rate on your loan %: ");
annual_rate = input.nextDouble();
System.out.println();
DecimalFormat f = new DecimalFormat("$#,###,###.00");
// Setup a counter to count payments
int count = 1;
// Get our standard payment which is 1/360 of loan
payment = (ending_balance / 360.0);
while (ending_balance > 0.0) {
new_balance = ending_balance;
// Calculate interest by multiplying rate against balance
interest_paid = new_balance * (annual_rate / 12.0);
// Subtract interest from your payment
principle_paid = payment - interest_paid;
// Subtract final payment from running balance
ending_balance = new_balance - principle_paid;
// If the balance remaining plus its interest is less than payment amount
// Then print out 0 balance, the interest paid and that balance minus the interest will tell us
// how much principle you paid to get to zero.
if ((new_balance + interest_paid) < payment) {
System.out.println(count + ". Payment: " + f.format(new_balance + interest_paid) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(new_balance - interest_paid) + " Loan Balance is: $0.00");
}
else {
// Lets show the table, loan, interest, and payment made towards principle
System.out.println(count + ". Payment: " + f.format(payment) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(principle_paid) + " Loan Balance is: " + f.format(ending_balance));
}
count++;
}
}
}
Need help with Java Amortization codeNeed help with Java Amortization code
Page 1 of 1
2 Replies - 1301 Views - Last Post: 08 March 2008 - 06:21 PM
Replies To: Need help with Java Amortization code
#2
Re: Need help with Java Amortization code
Posted 08 March 2008 - 06:16 PM
If u can edit ur post and place ur code in the follow tags:
[code*]
[/code*]
Without the *
Its easier to read it like that
[code*]
[/code*]
Without the *
Its easier to read it like that
#3
Re: Need help with Java Amortization code
Posted 08 March 2008 - 06:21 PM
AbuJaFaR, on 8 Mar, 2008 - 06:16 PM, said:
If u can edit ur post and place ur code in the follow tags:
[code*]
// java package
import java.text.DecimalFormat;
import java.util.Scanner;
// This will calculate a 30yr mortgage monthly payment
public class DavisMortgageCal2
{
public static void main(String[] args)
{
// declare variables
double intrest,payment;
int ammount,term;
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
intrest=.0575;
ammount=200000;
term=30;
payment=(ammount*((intrest/12)/(1-Math.pow((1+(intrest/12)),-(term*12)))));
// Calculator outputs
System.out.println("Principal="+ammount);
System.out.println("intrest rate="+intrest*100);
System.out.println("Years="+term);
System.out.println("Number of payments="+term*12);
System.out.print("Monthly Payment=");
System.out.println(decimalPlaces.format(payment));
Scanner input = new Scanner(System.in);
System.out.print("Please enter the original loan amount $ (-1 to end the program): ");
ending_balance = input.nextDouble();
System.out.print("Enter the interest rate on your loan %: ");
annual_rate = input.nextDouble();
System.out.println();
DecimalFormat f = new DecimalFormat("$#,###,###.00");
// Setup a counter to count payments
int count = 1;
// Get our standard payment which is 1/360 of loan
payment = (ending_balance / 360.0);
while (ending_balance > 0.0) {
new_balance = ending_balance;
// Calculate interest by multiplying rate against balance
interest_paid = new_balance * (annual_rate / 12.0);
// Subtract interest from your payment
principle_paid = payment - interest_paid;
// Subtract final payment from running balance
ending_balance = new_balance - principle_paid;
// If the balance remaining plus its interest is less than payment amount
// Then print out 0 balance, the interest paid and that balance minus the interest will tell us
// how much principle you paid to get to zero.
if ((new_balance + interest_paid) < payment) {
System.out.println(count + ". Payment: " + f.format(new_balance + interest_paid) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(new_balance - interest_paid) + " Loan Balance is: $0.00");
}
else {
// Lets show the table, loan, interest, and payment made towards principle
System.out.println(count + ". Payment: " + f.format(payment) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(principle_paid) + " Loan Balance is: " + f.format(ending_balance));
}
count++;
}
}
}
[/code*]
Without the *
Its easier to read it like that
[code*]
// java package
import java.text.DecimalFormat;
import java.util.Scanner;
// This will calculate a 30yr mortgage monthly payment
public class DavisMortgageCal2
{
public static void main(String[] args)
{
// declare variables
double intrest,payment;
int ammount,term;
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
intrest=.0575;
ammount=200000;
term=30;
payment=(ammount*((intrest/12)/(1-Math.pow((1+(intrest/12)),-(term*12)))));
// Calculator outputs
System.out.println("Principal="+ammount);
System.out.println("intrest rate="+intrest*100);
System.out.println("Years="+term);
System.out.println("Number of payments="+term*12);
System.out.print("Monthly Payment=");
System.out.println(decimalPlaces.format(payment));
Scanner input = new Scanner(System.in);
System.out.print("Please enter the original loan amount $ (-1 to end the program): ");
ending_balance = input.nextDouble();
System.out.print("Enter the interest rate on your loan %: ");
annual_rate = input.nextDouble();
System.out.println();
DecimalFormat f = new DecimalFormat("$#,###,###.00");
// Setup a counter to count payments
int count = 1;
// Get our standard payment which is 1/360 of loan
payment = (ending_balance / 360.0);
while (ending_balance > 0.0) {
new_balance = ending_balance;
// Calculate interest by multiplying rate against balance
interest_paid = new_balance * (annual_rate / 12.0);
// Subtract interest from your payment
principle_paid = payment - interest_paid;
// Subtract final payment from running balance
ending_balance = new_balance - principle_paid;
// If the balance remaining plus its interest is less than payment amount
// Then print out 0 balance, the interest paid and that balance minus the interest will tell us
// how much principle you paid to get to zero.
if ((new_balance + interest_paid) < payment) {
System.out.println(count + ". Payment: " + f.format(new_balance + interest_paid) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(new_balance - interest_paid) + " Loan Balance is: $0.00");
}
else {
// Lets show the table, loan, interest, and payment made towards principle
System.out.println(count + ". Payment: " + f.format(payment) + " Interest: " + f.format(interest_paid) + " Principle: " + f.format(principle_paid) + " Loan Balance is: " + f.format(ending_balance));
}
count++;
}
}
}
[/code*]
Without the *
Its easier to read it like that
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|