0

Hello I am attempting to write a program that calculates a future investment value using a fixed rate and I am having issues with my variables. Any help would be much appreciated thank-you ahead of time!

  /**
  * NAME:
  * DATE: November 3, 2015
  * FILE: 
  * COMMENTS: This program caculates a future investment value using a fixed rate
  */
  import java.util.Scanner;

public class lab12
{
   public static void main(String[] args)
   {
   //declare variables
   double yearlyInterstRate;
   double monthlyInterestRate;
   double monthlyInvestmentAmount;
   double years;
   double months;

   //Create Scanner Object
   Scanner keyboard= new Scanner(System.in);

   //Get Investment Information
   System.out.print("Hello we will be caculating the future of your fixed monthly investment, I will need to collect some information from you.");
   System.out.print("What is your monthly investment amount?");
   monthlyInvestmentRate=keyboard.nextLine();
   System.out.print("How many years wil you be investing for?");
   years=keyboard.nextLine();
   System.out.print("What is your yearly interest rate?");
   yearlyInterestRate=keyboard.nextLine();
   //Caculate the future rate
   {
      months=years*12;
      monthlyInterestRate=yearlyInterestRate/12/100;
      futureValue= CaculateFuturevalue(monthlyInvestedAmount,monthlyInterestRate,months);
      System.out.print("Your future value is $"+futureValue);
    }
 } //Close Main
} //close lab12
  • 2
    And the error is...? *Always* give complete details of the error - the exact error message, and where it's occurring. – Jon Skeet Nov 25 '15 at 07:24
  • 1
    *"having issues with variables"*. Please be more specific. Read "[How do I ask a good question?](http://stackoverflow.com/help/how-to-ask)". – Andreas Nov 25 '15 at 07:25
  • 1
    Also, take a look here, this may help: http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean – rb612 Nov 25 '15 at 07:25
  • 1
    `yearlyInterstRate` is misspelled. `monthlyInvestmentAmount` is not same as `monthlyInvestedAmount` and both are unassigned before use. `futureValue` is undefined. `nextLine()` returns a `String`, but you're assigning to a `double`, so use `nextDouble()` instead. – Andreas Nov 25 '15 at 07:29

2 Answers2

1

You have a misspelling in variables.

You have declared yearlyInterstRate but you're using yearlyInterestRate, so you need to use the variables as they were declared.

also you need to use monthlyInvestmentAmount not monthlyInterestRate as well.

Salah
  • 8,567
  • 3
  • 26
  • 43
1

This code will do:

public class lab12
{
    public static void main(String[] args)
    {
        //declare variables
        double yearlyInterstRate;
        double monthlyInterestRate;
        double monthlyInvestmentAmount=0; // you forgot to initialize this value
        double years;
        double months;
        double futureValue;
        //Create Scanner Object
        Scanner keyboard= new Scanner(System.in);

        //Get Investment Information
        System.out.print("Hello we will be caculating the future of your fixed monthly investment, I will need to collect some information from you.");
        System.out.print("What is your monthly investment amount?");
        monthlyInterestRate=keyboard.nextDouble();
        System.out.print("How many years wil you be investing for?");
        years=keyboard.nextDouble();
        System.out.print("What is your yearly interest rate?");
        yearlyInterstRate=keyboard.nextDouble();
        //Caculate the future rate

            months=years*12;
            monthlyInterestRate=yearlyInterstRate/12/100;
            futureValue= caculateFuturevalue(monthlyInvestmentAmount,monthlyInterestRate,months);
            System.out.print("Your future value is $"+futureValue);

    } 
}

Now some improvements:

  1. use nextDouble() instead of nextLine(), bacause your variables are double, not String.
  2. name your class from upperCase, so Lab12, and not lab12
  3. argumen validation would be nice (check if given values are grater than zero)
Beri
  • 11,470
  • 4
  • 35
  • 57