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 4 of 4

Thread: investment interest display problem

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default investment interest display problem

    hello first year Java student here, I have an assignment to write a program that asked for an investment amount, and interest rate. then calculates it over 30 years and displays it in a list like this:
    //what output should look like:

    enter investment amount :
    enter amount of interest:

    year cd value
    1 $value 1 year interest
    2 $value 2 years interest
    .
    .
    29 $value 29 years interest
    30 $value 30 years interest


    here is the code I have written so far


    package assign3;

    /**
    *
    * @author david
    */import java.util.Scanner;

    public class assing3 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // get info from the user
    Scanner input = new Scanner(System.in);
    System.out.print ("Enter investment amount: ");
    double investmentAmount = input.nextDouble();
    System.out.print("Enter yearly interest amount: ");
    double yearlyInterestRate = input.nextDouble();
    int years = 30;
    double cdGain = investmentAmount * (yearlyInterestRate * .01);
    double newInvestmentAmount = cdGain + investmentAmount;
    System.out.println("new investment amont is: " + newInvestmentAmount);

    //print the interst table
    printTotal( investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
    //compute interst amount for each year.

    }

    static void printTotal(double investmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
    printTotalHeading(investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
    printTotalbody(investmentAmount, yearlyInterestRate, years, cdGain, newInvestmentAmount);
    }
    //print the heading
    static void printTotalHeading(double investmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
    System.out.println("Months: CD Value: ");
    System.out.println("---------------------------------");
    }
    //printing the years and values
    static void printTotalbody(double newInvestmentAmount, double yearlyInterestRate, int years, double cdGain, double newInvestmentAmount){
    int i = 0;
    for ( i=0;i < years; i++)

    System.out.println(i+1 +" " + newInvestmentAmount );

    }
    }


    I am stumped on how to get the interest to compound and print in order next to the corresponding year.


    any help would be appreciated,


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: investment interest display problem

    how to get the interest to compound
    Do you have an equation for this? Must be one online. try google.

    print in order next to the corresponding year.
    What does the program output now?


    Please enclose your code in code tags to preserve formatting. See: BB Code List - Java Forums

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: investment interest display problem

    currently the output is

    enter investment amount: (user input1)
    enter yearly interest rate : (user input2)
    new investment amount is: user input1 * user input2 * .01
    year CD value
    -------------------------
    1 user input1
    2 .
    . .
    .
    29
    30

    not sure how to get the cd value to keep compiling?

    thanks in advance.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: investment interest display problem

    how to get the cd value to keep compiling
    Please explain what "keep compiling" means? I computer sci terms to compile is to convert source code to object code.

    I don't understand the output you posted. Your code shows that something more should be printed:
    System.out.println(i+1 +" " + newInvestmentAmount );

    What is the value of newInvestmentAmount? Why didn't it show on the printout?

Similar Threads

  1. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  2. GridBagLayout display problem
    By mjpam in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 5th, 2011, 04:58 PM
  3. Display Image (png)
    By vimalaranjan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2011, 06:44 PM
  4. display pdf file into jpanel problem
    By Jhovarie in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 12th, 2011, 02:29 PM
  5. Display file name
    By Puk284 in forum Java Servlet
    Replies: 1
    Last Post: April 13th, 2010, 03:13 AM