Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class GravityCalculator {
double gravity;
double initialVelocity;
double fallingTime= 10.0;
double initialPosition;
public GravityCalculator(double a, double t, double vi, double xi){ //Default Constructor
this.gravity=a;
this.fallingTime=t;
this.initialVelocity=vi;
this.initialPosition=xi;
}
public double finalPosition(){ //Method
return 0.5 * (this.gravity)*((this.fallingTime)*(this.fallingTime)) + (this.initialVelocity)*(this.fallingTime) + (this.initialPosition);
}
public static void main(String[] arguments) {
GravityCalculator x = new GravityCalculator(-9.81,10.0,0.0,0.0); //(arguments)
System.out.println("Final Position:"+ x.finalPosition());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.