Question: Intro to Java exercise Compute the positions of your cannonball Suppose a cannonball is propelled vertically into the air with a starting velocity v0. Any

Intro to Java exercise

Compute the positions of your cannonball

Suppose a cannonball is propelled vertically into the air with a starting velocity v0. Any calculus book will tell us that the position of the ball after t seconds is s(t) = -0.5 * g * t2 + v0 * t, where g = 9.81 m/sec2 is the gravitational force of the earth. In fact, we will confirm the theorem from calculus by a simulation. In our simulation, we will consider how the ball moves in very short time intervals deltaT. In a short time interval the velocity v is nearly constant, and we can computer the distance the ball moves as deltaS = v. In our program, we will simply set double deltaT = 0.01 and update the position by s = s + v * deltaT. The velocity changes constantly - in fact, it is reduced by the gravitational force of the earth. In a short time interval, v decreases by g * deltaT, and we must keep the velocity updated as v = v - g * deltaT. In the next iteration the new velocity is used to update the distance. Now run the simulation until the cannonball falls back to the earth. Get the initial velocity as an input (100 m/sec is a good value). Update the position and velocity 100 times per second, but only print out the position every full second. Use a class Cannonball and a CannonballTest class. What is the benefit of this kind of simulation when an exact formula is available? Well, the formula from the calculus book is not exact. Actually, the gravitational force diminishes the farther the cannonball is away from the surface of the earth. This complicates the algebra sufficiently that it is not possible to give an exact formula for the actual motion, but the computer simulation can simply be extended to apply a variable gravitational force. For cannonballs, the calculus-book formula is actually good enough, but computers are necessary to compute accurate trajectories for higher-flying objects such as ballistic missiles.

Important: be sure to handle for illegal arguments with exceptions.

You can assume an initial angle of 45 degrees or ask the user to input an angle.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!