In this assignment, you will create a program that computes the distance an object will fall in Earth's gravity.
Create a new class called GravityCalculator.
Copy and paste the following initial version:
class GravityCalculator {
public static void main(String[] arguments){
double gravity =-9.81; // Earth's gravity in m/s^2
double initialVelocity = 0.0;
double fallingTime = 10.0;
double initialPosition = 0.0;
double finalPosition = 0.0;
System.out.println("The object's position after " + fallingTime +" seconds is "+finalPosition + " m.");
}
}
Run it
Modify the example program to compute the position of an object after falling for 10 seconds, outputting the position in meters. The formula in Math notation is:
x(t) = 0.5at2 + vit + xi
Variable
Meaning
Value
a
Acceleration (m/s2) -9.81
t
Time (s)
10
vi
Initial velocity (m/s) 0
xi
Initial position 0
Note: The correct value is -490.5 m. Java will output more digits after the decimal place, but that is unimportant.
Submit your GravityCalculator.java file along with the output you received when running it. The output should be captured as a screen capture or by cutting and pasting the output from the window that the output of your program is displayed in.