File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes using for loops in calculations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using for loops in calculations" Watch "using for loops in calculations" New topic
Author

using for loops in calculations

Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
My problem is the fact that i cannot get the loop to properly run correctly to calculate the second half table which is displayed with Months on the left and CD Value on the right. I just need to be pointed in the right direction, i have spent a lot of time trying to figure this out. thanks for taking the time to look at my code.


Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

are you sure all of the formulas for percent yield, monthly yield are correct?


"If the facts don't fit the theory, get new facts" --Albert Einstein
Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
the ones before the loop i know are correct, once i figure out how to properly loop the math part ill know if my the equation in the loop is correct. i believe it is though.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

So I think I see what you're trying to do here, for the loop part you want to print out the number of months from 1 to (whatever the user enters) right? Then you want to calculate how much money is gained on the cd per month and display it across from the month. is this right??
Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
yup, then its prints out like:
Months
1
2
3
etc

CD Value
original + 1 month of interest
and so on

except months is across from CD Value.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Ok, I know what you're doing wrong, you have a few problems here.
First this formula:

is wrong.

if my deposit is 500 and my annual % yield is 2% then this returns 500.83333333, this is the total i accumulated not the amount yield per month.
the correct formula is:


Second, you don't need to redefine monthlyYield as monthlyYield1, because it doesnt change from month to month, its constant.

Third, you dont need two for loops, you only need one.
declare a new variable to hold to total cd value;
example:


hope this helps
Hunter.
Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
thanks alot for the help it is very much appreciated. i gotta say this site is much more beginner friendlier than others.
Piet Souris
Ranch Hand

Joined: Mar 08, 2009
Posts: 443
    
    5
Note however that the code above is correct, provided you don't need to work with compound interest, which is very unusual (especially when the number of months is more than 12).

Greetings,
Piet
 
jQuery in Action, 2nd edition
 
subject: using for loops in calculations
 
Similar Threads
Could not find symbol class.
Format the output
output prints null
Multidimensional Arrays problem
Change Due/Tendered Program