r/programminghelp • u/anzsrouxjoyeuse • Jan 15 '21
Java JAVA- KINETIC ENERGY
Hello experts and fellow learns, I'm stuck with this problem for a while and utilize all resources that I have for this activity but I can't seem to get it right. This is also a self study as Im not able to understand the lesson from our class due to poor internet connection, I need to call a function to get the object's kinetic energy. I appreciate your suggestions, tips, and helps etc. Thanks in advance.
This is my code:
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
double KE, m, v, ObjectKE;
System.out.print("Enter mass in kilograms:");
m = input.nextDouble();
System.out.print("Enter velocity in meters per second:");
v = input.nextDouble();
System.out.print("The object's kinetic energy is:");
KE= input.nextDouble();
System.out.print("The object's kinetic energy is: " + ObjectKE + "J");
}
public static double KineticEnergy (double m , double v){
double ObjectKE = (m * (0.5) * (Math.pow(v,2)));
return ObjectKE;
}
}
Result:/MyClass.java:12: error: variable ObjectKE might not have been initialized
System.out.print("The object's kinetic energy is: " + ObjectKE + "J");
^
1 error
1
u/anzsrouxjoyeuse Jan 15 '21
Thank you. However, can you explain it to me a little bit further? if its okay?