Click to See Complete Forum and Search --> : how do i display data using a table (please help)


nickpass17
03-29-2010, 12:23 AM
hey everyone,

i have to write a method that computes future investment value at a given interest rate for a specified number of years.

Write a test program that prompts the user to enter the investment amount, and the interest rate, and prints a table that displays future value for the years 1 to 30.

this is the code that i have so far:



import java.util.Scanner;

public class Investment
{
public static void main (String []args)
{
double futureInvestmentValue;
double investmentAmount;
double monthlyInterestRate;
double rate;
int years;

Scanner input = new Scanner (System.in);

System.out.print("Enter the amount invested:");
investmentAmount = input.nextDouble();

System.out.print("Enter the annual interest rate:");
rate = input.nextDouble();

System.out.print("Enter number of years:");
years = input.nextInt();

monthlyInterestRate = rate/1200;

futureInvestmentValue = investmentAmount*Math.pow((1+monthlyInte…

System.out.println("The future value is " +futureInvestmentValue);
}
}


****the part that i need help with is, how do i print a table that displays the future value for the years from 1 to 30? and i guess i dont need to prompt the user for the years then.

if anyone could please help me, it will be greatly appreciated.

Khalid Ali
03-29-2010, 04:46 AM
if I understand correctly, then run a loop upto 30 and then do the calculation in the loop for x, where x is the year(1,2,3,4 etc)
and print each year once its calculated