Working on a code to calculate interest rates...

So i am supposed to calculate someones savings+their interest rate for each month, but it only wants me to display the 6th month. I am lost how to get to the 6th month. I made the code work for the first one and for an example i used 100 as the savings and .05 as the interest. any help would be appreciated. Code so far is:

Code java:

import java.util.Scanner;
import javax.swing.JOptionPane;
//September 19, 2012 pg 77 #2.13
public class Pg77 {
public static void main(String[] args) {
String numtxt= JOptionPane.showInputDialog("Enter a monthly savings amount.");
Double savings = Double.parseDouble(numtxt);
numtxt = JOptionPane.showInputDialog("Enter annual interest rate as a decimal i.e. 5%=.05");
Double arate = Double.parseDouble(numtxt);
Double rate=arate/12;
Double interest=rate*savings;
JOptionPane.showMessageDialog(null, savings + "*" + rate + "=" + interest);
Double year1=interest+savings;
JOptionPane.showMessageDialog(null, savings + "+" + interest + "=" + year1);
}
}

Re: Working on a code to calculate interest rates...

Please Edit your post and wrap your code with

[code=java]

<YOUR CODE HERE>

[/code]

to get highlighting and preserve formatting.

Quote:

how to get to the 6th month.

Does that mean to compute the first 5 months and not display them? You could use a loop to compute the first 5 months.

Re: Working on a code to calculate interest rates...

Thanks for that. the first 5 months can be displayed in the code, but the 6th is all that is wanted in the dialog box after running the program. I just didnt know if i had to manually put in all the months or if I could use some shortcut command that I was unaware of

Re: Working on a code to calculate interest rates...

Quote:

I just didnt know if i had to manually put in all the months

Look at using a loop.

Re: Working on a code to calculate interest rates...

Re: Working on a code to calculate interest rates...

I don't know what formulas you have for computing interest and compounding it.

Here's some pseudo code:

set principle amt to start with

begin loop (to loop number of periods)

compute interest on principle for this period

add interest to principle

end loop

Re: Working on a code to calculate interest rates...

Hey Norm,

I thought this problem would be great for my education, so I tried to solve it. I ran into trouble with the loop. I have trouble incrementing it. I took his numbers and when I enter it in the loop i just get the loop to repeat the formula over and over again. If i use the increment of x, then it adds one to it, but it actually some what works Does that make sense?

Re: Working on a code to calculate interest rates...

If you are having problems with the code, post the code and your questions.

Also post the output from the program and explain what is wrong with it.