import java.util.Scanner;
public class FutureInvestment {
public static void main(String[] args) {
// Display name
System.out.println("Programmed by ");
Scanner input = new Scanner(System.in);
// Prompt user to input investment amount
System.out.print("Enter an investment amount: ");
double investment = input.nextInt();
// Prompt user to input interest amount
System.out.print("Enter an interest rate: ");
double interest = input.nextInt();
// Prompt user to input number of years
System.out.print("Enter the number of years: ");
int time = input.nextInt();
// Set values at new variables
double a = investment;
double i = interest;
// Get MONTHLY interest rate from YEARLY interest rate.
double mi = i / 12;
int y = time;
double m = futureInvestmentValue(a,mi,y);
//result
System.out.println(amount);
}
//Create method for interest rate
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years){
int year = 1;
double amount;
// Create formula
while (year <= years)
amount = investmentAmount * monthlyInterestRate * year;
year++;
return amount;
}
}
my program doesn't seem to work correctly. it says that the amount variable has not been initialized. however, i am at a loss as to what it should be set to. also. when i set amount to "0" the program compiles but when i enter all the values nothing happens and the program still continues to run instead of terminate.
does anyone have any suggestions?
how do you terminate the program if the user enters 0 for any value?
thanks ahead of time!