Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

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

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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:

    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);
        }
    }
    Last edited by ColeTrain; September 19th, 2012 at 08:15 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    I just didnt know if i had to manually put in all the months
    Look at using a loop.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    how do i do that?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jun 2012
    Posts
    105
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default 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?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM
  2. Why isn't this code working?
    By tai8 in forum What's Wrong With My Code?
    Replies: 33
    Last Post: March 12th, 2012, 03:23 PM
  3. Calculate Button Not Working
    By czerenborg in forum AWT / Java Swing
    Replies: 8
    Last Post: September 8th, 2011, 09:25 PM
  4. investment interest display problem
    By df75douglas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 4th, 2011, 07:32 AM
  5. Getting code working with gui
    By Nostromo in forum AWT / Java Swing
    Replies: 2
    Last Post: March 21st, 2011, 09:34 PM