Solved

calculation

Posted on 2006-05-31
249 Views
Last Modified: 2010-03-31
I am trying to get the below amortization calculation to work for a mortgage program. The mortgage payment calculation works fine but i get an error on variable when i go to create the amortization schedule. is something wrong??

double newRate = rateValue / 100;
double J = newRate / 12;
//double moInC=(newRate*12)/100;

// to display amount in correct format
DecimalFormat df = new DecimalFormat("\$#,###.00");

double mortgage = (Math.pow((1 + J), termValue) - 1)
/ (J * Math.pow((1 + J), termValue));
double payment = amountValue / mortgage; // *Rate Calculation

gui.paymtField.setText("" + df.format(payment));

}

/*double newPrinC = amountValue;                  <------------------this is the amortization that does not work.
{
for (int i = 0; i <= 480; i++)
{

double newInC = J * newPrinC;
double reductionC = payment - newInC;
newPrinC = newPrinC - reductionC;

gui.textField.append("");
gui.textField.append(" " + +i);
gui.textField.append(" " + "\t" + df.format(newInC));
gui.textField.append(" " + "\t" + df.format(reductionC));
gui.textField.append(" " + "\t" + df.format(newPrinC) + "\n");
}
}//*/
0
Question by:pgmtkl
7 Comments

LVL 2

Expert Comment

This line of code looks a little strange.  What are you trying to do here.  I would expect the compiler to complain about it.

gui.textField.append(" " + +i);
0

LVL 13

Expert Comment

if  gui.textField  is a TextField/JTextField, then you should use TextArea/JTextArea instead.

0

Author Comment

The text field area is ok, this is a gui program. The mortgage payment calculation works fine and displays the amount on the gui screen. Howver when i go to add the amortization portion i get error symbol  : variable J
location: class ThursdaySupportWeek4
double newInC = J * newPrinC;
^
1 error.

the j variable is defined but does not work in this section and i do not know why

double newPrinC = amountValue;                  <------------------this is the amortization that does not work.
{
for (int i = 0; i <= 480; i++)
{

double newInC = J * newPrinC;
double reductionC = payment - newInC;
newPrinC = newPrinC - reductionC;

0

LVL 2

Assisted Solution

I see a close brace at the end of the code section that defines variable J.  It would appear that the definition is enclosed in braces that make it defined locally to that secion and not visible to the later code.

double newRate = rateValue / 100;
double J = newRate / 12;
//double moInC=(newRate*12)/100;

// to display amount in correct format
DecimalFormat df = new DecimalFormat("\$#,###.00");

double mortgage = (Math.pow((1 + J), termValue) - 1)
/ (J * Math.pow((1 + J), termValue));
double payment = amountValue / mortgage; // *Rate Calculation

gui.paymtField.setText("" + df.format(payment));

}
0

LVL 13

Accepted Solution

in the following :

gui.paymtField.setText("" + df.format(payment));

}              //  <-- to be removed

/*double newPrinC = amountValue;
{              //  <-- to be removed
for (int i = 0; i <= 480; i++)

0

Author Comment

removing that set of braces worked. thanks
0

LVL 13

Expert Comment

:-)
0

Join & Write a Comment Already a member? Login.

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!