Solved

I am trying loop mortgage payments

Posted on 2005-03-15
Medium Priority
267 Views
import java.text.*;

public class mortgage
{
//private member variables declared static for now

double loanamount  = 200000.00;      //Total mortgage payment
double loanterm    = 30.00;      //Length of years for loan
double interestrate  = 0.0575;      //Interest rate for loan

double monthlyprinciple;
double loanbalance = 0.0;
double monthinterest;

int payment = 0;
int months = 0;

void main(String[] args)  //Entry point. Only one can exist per class and invocation.
{

double monthlyinterest = interestrate/12;      //Months in a year for loan
double monthlyterm = loanterm*12;      //Monthly precentage rate

//convert to monthly terms
double monthlytotal=(Math.pow((1+monthlyinterest),monthlyterm)-1)/(monthlyinterest*Math.pow((1+monthlyinterest),monthlyterm));
double monthlypayment = loanamount/monthlytotal;

//Format values as currency for the default locale.
String monthlypaymenttotal = java.text.NumberFormat.getCurrencyInstance().format(monthlypayment);
String totalloanamount = java.text.NumberFormat.getCurrencyInstance().format(loanamount);

//Output the results by field.
System.out.println("-----------------------------------------------------------");
System.out.println("Total Loan Amount: " + totalloanamount);
System.out.println("Interest Rate: " + 100 * interestrate);
System.out.println("Loan Term: " + loanterm);
System.out.println("-----------------------------------------------------------");
System.out.println("Total Monthly Payment: " + monthlypaymenttotal);

while (loanamount >= 0.01) //Loop ends when loan is below one penny
{   //loop loan payment
monthlyinterest = (loanamount * interestrate);
monthlyprinciple = monthlypayment - monthinterest;
loanbalance = loanamount - monthlyprinciple;   //calculates new principal
loanamount = loanbalance;
payment++;
months++;
if (months == 6)
{   //pauses to show payments
pause(3600);
months= 0;
}
System.out.println("\n\nPayment Number:" + payment+ "\n------------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount of Interest Paid = " + form.format(monthinterest));

}
}

public static void pause(int duration) {   //sets up pause object
try
{
}
catch (InterruptedException e) {}
}
}

Error
mortgage.java:74: cannot resolve symbol
symbol  : variable form
location: class mortgage
System.out.println("\n\nPayment Number:" + payment+ "\n
-----------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount o
Interest Paid = " + form.format(monthinterest));

^
mortgage.java:74: cannot resolve symbol
symbol  : variable form
location: class mortgage
System.out.println("\n\nPayment Number:" + payment+ "\n
-----------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount o
Interest Paid = " + form.format(monthinterest));

^
2 errors

E:\Documents and Settings\sublime\Desktop\University of Phoenix\POS_406\Program
>
0
Question by:sublime76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 19

Expert Comment

ID: 13552446

NumberFormat form = NumberFormat.getCurrencyInstance();

just before the System.out.println referencing form on line 74.

BTW, when you try to test this you'll find that it won't run (or I don't think it will) because the main method must be defined as public static. Change your class like this and you'll get better results:

Replace:

void main(String[] args) {

with:

public static void main(String[] args) {
new Mortgage().run();
}

public void run() {

Best regards,
Jim Cakalic
0

LVL 19

Accepted Solution

Jim Cakalic earned 2000 total points
ID: 13552476
Oh, yeah -- make sure to add an import of java.text.NumberFormat. Eclipse does it for me so I sometimes forget to make it part of my post.

Jim
0

Author Comment

ID: 13559957
Thanks but I already fixed it.  Here is what the program needs to look like.  I do appreciate you help though.

import java.text.*;

class mortgage
{
//private member variables declared static for now

public static void main(String[] args)  //Entry point. Only one can exist per class and invocation.

{

double loanamount  = 200000.00;      //Total mortgage payment
double loanterm    = 30.00;      //Length of years for loan
double interestrate  = 0.0575;      //Interest rate for loan

double monthlyprinciple;
double loanbalance = 0.0;
double monthinterest;

int payment = 0;
int months = 0;

double monthlyinterest = interestrate/12;      //Months in a year for loan
double monthlyterm = loanterm*12;      //Monthly precentage rate

NumberFormat form = NumberFormat.getCurrencyInstance();   //creates form object

//convert to monthly terms
double monthlytotal=(Math.pow((1+monthlyinterest),monthlyterm)-1)/(monthlyinterest*Math.pow((1+monthlyinterest),monthlyterm));
double monthlypayment = loanamount/monthlytotal;

//Format values as currency for the default locale.
String monthlypaymenttotal = java.text.NumberFormat.getCurrencyInstance().format(monthlypayment);
String totalloanamount = java.text.NumberFormat.getCurrencyInstance().format(loanamount);

//Output the results by field.
System.out.println("-----------------------------------------------------------");
System.out.println("Total Loan Amount: " + totalloanamount);
System.out.println("Interest Rate: " + 100 * interestrate);
System.out.println("Loan Term: " + loanterm);
System.out.println("-----------------------------------------------------------");
System.out.println("Total Monthly Payment: " + monthlypaymenttotal);

while (loanamount >= 0.01) //Loop ends when loan is below one penny
{   //loop loan payment
monthinterest = (loanamount * interestrate);
monthlyprinciple = monthlypayment - monthinterest;
loanbalance = loanamount - monthlyprinciple;   //calculates new principal
loanamount = loanbalance;
payment++;
months++;
if (months == 6)
{   //pauses to show payments
pause(3600);
months= 0;
}
System.out.println("\n\nPayment Number:" + payment+ "\n------------"+ "\nTotal Loan Balance = " + form.format(loanamount) + "\nAmount of Interest Paid = " + form.format(monthlyinterest));

}
}

public static void pause(int duration) {   //sets up pause object
try
{
}
catch (InterruptedException e) {}
}
}
0

LVL 19

Expert Comment

ID: 13560375

Regards
Jim
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll