Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Created May 4, 2016 01:52
Show Gist options
  • Save gilrg18/4c038c70ff4271627a84451aa51864bf to your computer and use it in GitHub Desktop.
Save gilrg18/4c038c70ff4271627a84451aa51864bf to your computer and use it in GitHub Desktop.
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