Market research has indicated that the app store currently lacks a catapult calculator. Filling this void could be the get rich opportunity of a lifetime! Write a program that calculates whether a rock flung from a catapult will make it over a wall and hit a target. Your program should work for the scenario below:
There is a 75 foot tall wall and the target is located 150 feet past it. The target is 50 feet wide—we will ignore the height of the target and assume that anything that lands within the area of its base would hit the target. The catapault always launches rocks at a 45 degree angle, and to make life easy we will assume that they are launched from a height of 0 feet.
Your program should read in a distance the catapault is from the wall (in feet) and an initial velocity for the rock it throws and report whether the shot: hits the wall, is too short, is too long, or hits the target. If the shot does not hit the wall, report how far it traveled in total.
This summary of projectile motion has the equations you will need. In particular, you will need the Parabolic Trajectory equation that gives a height for the rock after it travels feet and the Range equation.
Your program is reading in u (initial velocity). Use the value 32.17405 for g and 3.14159265359 for pi.
Because doubles have inherit limits to their accuracy, you should not use
!= to compare them. Instead of “if x == y” you should write “if the difference between x and y is small enough”. The standard way to do that is something like:
abs(x - y) < 0.0001. (Book section 3.6 part 6)