//this code should calculate future investment but is not
//it should print years from 1 to 30 and future value
// i'm new in java please help me out.thnks adv
import java.util.Scanner;
public class C5E7{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
//double k = futureInvestementValue( a, b, c, d);
System.out.println(" enter amount invest:");
double investmentAmount = input.nextDouble();
System.out.println(" enter monthly Rate");
double rate = input.nextDouble();
System.out.println("THE AMOUNT INVESTED IS:" + investmentAmount);
System.out.println("THE ANNUAL INTEREST RATE IS:" + rate);
for( int i = 1; i <= 30; ++years)
System.out.println(years + "\t\t" + futureInvestmentValue);
System.out.println("YEARS\t\tFUTURE VALUE");
{
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate int years)
{
// double monthlyInterestRate;
result = 0;
// monthlyInterestRate = rate /12;
futureInvestmentValue = investmentAmount * (1+ monthlyInterest)numberOfYears * 12;
years = years + 1;
double result = futureInvestmentValue;
return result;
}
One easy to spot problem is with your parameters -
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate int years)
{
// double monthlyInterestRate;
result = 0;
// monthlyInterestRate = rate /12;
futureInvestmentValue = investmentAmount * (1+ monthlyInterest)numberOfYears * 12;
years = years + 1;
double result = futureInvestmentValue;
return result;
}
change the parameters inside the parintheses,
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
you forgot the comma. There must be a comma between each parameter, next error, :
//double k = futureInvestementValue( a, b, c, d);
get rid of those
// comment tags, i got no clue why they're there, and your method has 3 parameters while you declare 4 arguments. I dont see where the variables a b c and d came from or why its called k. if this was supposed to be a comment, where did you try calling the method then? and theres another error, you tried acessing local variables from your method in main. that will not work, they are only accessible from their method. instead return the value of the variable you want to access in your method. to get it use syntax in main:
yourVariable = futureInvestmentValue(argument 1, argument 2, argument 3);
(write code with that syntax in main, then you can access the value it returns). right now, with your code as it is you can only acess the methods return value, result in any other method besides futureInvestmentValue
you used a static method. a better approach is try using a non-static first, which is after all the point of OOP. to call non statics use syntax:
yourClassName yourObjectName = new yourClassName(); /* use arguments inside parentheses if you have parameters in your constuctor. (if you have one. if you dont, you should still declare an empty constructor.*/
variableType yourVariableName = yourObjectName.futureInvestmentValue(arguments);
you can then use it in your program.
example:
public class accessDemo {
public static void main(String[] args) {
acessDemo acdemo = new acessDemo();
double acessmethodreturn = acDemo.futureInvestmentValue(arguments);
// then you can use it in your program.
acDemo can be named anything you want. if your constructor has parameters write the arguments in new accessDemo(write the arguments here);
write whatever the arguments need to be for calling the method using the newly created object. also the name of the variable and type that gets the calls the method can be whatever is required/you want