posted 1 year ago

Hello Guys,

I'm very new to Java Programming and I require some help understanding few things ;)

I'm learning Java with a book called "Introduction to Java Programming" - Comprehensive Version by Y. Daniel Liang and I just had a topic to help me understand Software Development Process and in that I had an example code to calculate a Loan after x years with x interest rate.

This is my code

The thing is, I don't really understand how line no. 24 works

Any help would be much appreciated.

I'm very new to Java Programming and I require some help understanding few things ;)

I'm learning Java with a book called "Introduction to Java Programming" - Comprehensive Version by Y. Daniel Liang and I just had a topic to help me understand Software Development Process and in that I had an example code to calculate a Loan after x years with x interest rate.

This is my code

The thing is, I don't really understand how line no. 24 works

Any help would be much appreciated.

Norm Radder

Rancher

Posts: 2240

28

posted 1 year ago

That is an assignment statement that evaluates the expression that is to the right of the = and assigns its value to the variable to the left of the =. The statement also defines the variable: monthlyPayment as a double.

To see what the expression is doing, break it up into simple single operator expressions that save their values in separate variables.

For example with this expression:

x = y * (x - 2)

it could be broken into these 2 simple statements:

int part2 = (x - 2);

x = y * part2;

how line no. 24 works

That is an assignment statement that evaluates the expression that is to the right of the = and assigns its value to the variable to the left of the =. The statement also defines the variable: monthlyPayment as a double.

To see what the expression is doing, break it up into simple single operator expressions that save their values in separate variables.

For example with this expression:

x = y * (x - 2)

it could be broken into these 2 simple statements:

int part2 = (x - 2);

x = y * part2;

Norm Radder

Rancher

Posts: 2240

28

posted 1 year ago

Look at the API doc for the Math class's pow() method to see what it does: http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#pow-double-double-

That must be what the formula requires for it to get the correct answer. I don't know what that formula is for and can not help you understand why it is coded the way it is.

Do an internet search on the topic of computing monthly payments to find a better answer.

what does Math.pow

Look at the API doc for the Math class's pow() method to see what it does: http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#pow-double-double-

why is there (1 - 1)

That must be what the formula requires for it to get the correct answer. I don't know what that formula is for and can not help you understand why it is coded the way it is.

Do an internet search on the topic of computing monthly payments to find a better answer.

Hannah Leitheiser

Greenhorn

Posts: 1

Piet Souris

Master Rancher

Posts: 2044

75

posted 1 year ago

The formula is a well known one from elementary financial maths.

I wrote something about it in this topic:

(explanation of some financial formulas)

Grzegorz Skawinski wrote:I know what this line of code does.

I don't really get the Math.pow and the way why is there (1 - 1) before it and what does Math.pow do.

The formula is a well known one from elementary financial maths.

I wrote something about it in this topic:

(explanation of some financial formulas)