I'm a student and quite new to Java, I am trying to write a program to calculate someone's age given a hypothetical future year. I am learning methods and how to call from them so that is required for this program, but for some reason I can't get this to work. I feel like I must be close but am missing something obvious. I've tried a few different ways to make this work but have had no success. Currently I am getting a "cannot resolve symbol findfutureAge"
import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter your name: ");
String name = input.nextLine();
System.out.println("Please enter your age: ");
int age = input.nextInt();
System.out.println("Please enter a future year: ");
int futureYear = input.nextInt();
System.out.println("Your age would be " + findfutureAge);
}
public static int findFutureAge(int age, int futureYear) {
return futureYear - 2021 + age;
}
}
You are treating findfutureAge
as a variable, but there isn't such variable.
There is a method, findFutureAge
(case sensitive), but you'll need to add the parameters in order to actually call it.
Change the next line:
System.out.println("Your age would be " + findfutureAge);
to:
System.out.println("Your age would be " + findFutureAge(age, futureYear));