GRAVITY CALCULATOR JAVA TASK:
Create Java gravity calculator, able to determine the object’s final position after falling through the Earth’s atmosphere through the predetermined time. The initial parameters include: gravity (-9.81), falling time (10 seconds), as well as initial position and initial velocity of the object (both set to 0 by default). However the user should be able to modify the last 3 parameters according to his liking, with the calculator providing him with corresponding final position each time one of parameters changes.
In this sample we will need to use an equation to determine the final position of the object:
x(t) = 0.5 × a × t2 + vi × t + xi,
wherea – gravity = acceleration
t – time
vi – initial velocity
xi – initial position
Given these variables, our equation will look as following:
finalPosition = 0.5*gravity*fallingTime*fallingTime +initialVelocity*fallingTime + initialPosition;
This part of code makes sure that the user will be able to input nothing but digits (of double type) by ignoring the other kinds of input:
while (!in.hasNextDouble()) in.next();
We hope you found our gravity calculator java sample useful and it will help you to cope with your own projects. In case you still experience problems with IT assignment, you can count on us. We will provide java homework help with tasks of any difficulty level and deadline.
Check out also Java program for magic square sample that may come in handy in your studies.