Kat H.

# Catapult Calculator

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.

Hints:

Because doubles have inherit limits to their accuracy, you should not use == or != 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)

### Sample run 1: (user input in red)

Enter distance from wall: 200
Enter velocity: 100
Hits the wall!

### Sample run 2: (user input in red)

Enter distance from wall: 200
Enter velocity: 125
Too far!
Rock traveled 485.64 feet.

### Sample run 3: (user input in red)

Enter distance from wall: 200
Enter velocity: 105
Too short!
Rock traveled 342.667 feet.

### Sample run 4: (user input in red)

Enter distance from wall: 200
Enter velocity: 115
Too far!
Rock traveled 411.046 feet.

### Sample run 5: (user input in red)

Enter distance from wall: 200
Enter velocity: 110
Hit!
Rock traveled 376.079 feet.

### Sample run 6: (user input in red)

Enter distance from wall: 300
Enter velocity: 125
Hit!
Rock traveled 485.64 feet.

By:

Tutor
4.7 (31)

Math and computer tutor/teacher

## Still looking for help? Get the right answer, fast.

Get a free answer to a quick problem.
Most questions answered within 4 hours.

#### OR

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.