I am pretty new to coding and I have been having trouble with a Physics calculator I've been making. I made this trying to utilize OOP for a class project. The point I to let the user input the variables, then they get shipped into the equation on the class file, and then finally display the result. When I try to compile, it says that the function getAnswer can't see the result declared above it. I plan to make each of the 16 iterations of the equation, so I need to first figure out why this one doesn't work. Any answer is welcome.
-Thanks
import java.util.Scanner;
public class VFD {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Kinmatics calculator");
System.out.println("You can find Final Velocity, Acceleration, DIsplacemnt, or Time");
System.out.println("What variable is not included in the equation?");
String missing = keyboard.next();
System.out.println("What variable are you looking for?");
String find = keyboard.next();
if (missing.equals("Final Velocity") && find.equals("Initial Velocity")) {
System.out.println("Please enter your available values");
System.out.println("Acceleration = (m/s^2)");
double a = keyboard.nextDouble();
System.out.println("Displacement = (m)");
double d = keyboard.nextDouble();
System.out.println("Time = (s)");
double t = keyboard.nextDouble();
VelocityFinder qviadt = new VelocityFinder();
qviadt.qviadt(a, d, t);
System.out.println(qviadt.getAnswer());
}
}
}
This is the class file
public class VelocityFinder {
public void qviadt( double a, double d, double t ) {
double result = d/(.5*a*(t*t))/t;
double answer = result;
}
public String getAnswer () {
return answer;
}
}