Overview

You are a part of a team that will be completing at a Catapult Contest. Your team will be attacking the castle. The goal is to launch the catapult over the wall surrounding the castle but not go beyond the far castle wall. To help your team to victory, you need to write a program to calculate the trajectory of a projectile based on launch angles and launch velocities. It will create a matrix of all of the possible trajectories as well as the trajectories to help your team hit the target range. Review the information about calculating projectile trajectories in the Background Information section below. Look up the toRadians() and the sin() methods in the Java API for the Math class. Remember, the sin() method parameter must be in radians so the degrees given must converted to radians. Take time to plan your project. The program must use an OOP design.

Specifications

Rules

The program will create a Catapult object that will create a searchable matrix of trajectories for the given speeds and angles. The object should store these values in a 2D array. Given a target range of minimum and maximum distances, representing the near and far castle walls, the program should search the calculated trajectories and return a list of speed and angle combinations that can be used by your team to successfully launch the catapult. The output should be in an easy to read human readable format. If there are no speed and angle pairs in the current set that will accomplish the goal in the current matrix, the program should also graciously tell the users that they do not have a viable launch. The program will have a number of potential sets of speeds and angles. The program should be able to run the simulation as many times as indicated by the user (found in the text file). Input will be done from a text file rather than keyboard input.

The program will take input from a text file containing the following information on each line:

  • Number of sets
  • Number of speeds, followed by a list of speeds
  • Number of angles, followed by a list of angles
  • Minimum trajectory
  • Maximum trajectory

**speeds, angles, maximum and minimum repeated for the specified number of sets

Sample Text File contents: see image.

Expected Output:

When your program runs correctly, the program should output a table of possible distance values and under the table there should be a list of the speed and angle pairs that match. Note, there will be a series of projectile tables in the output - one for each of the tests. When the program is run, there should be a projectile table and a set of best trajectory values for each set. If there are 7 sets of data, there should be 7 tables in the output. The image below is an example for 1 set of data. The format of the output table should resemble the following, but with the appropriate data for each row and column.

Figure: see image.

Java Requirements

The program must utilize single dimensional arrays to store the speeds and angles. At a minimum, you will need one 2D array to store the values for the trajectories. How you define the logic and utilize these arrays is up to you.

The program must be created from an object-oriented perspective. Most of the work should be completed in the object class. The program must use methods appropriately.

Background Information: Trajectory of a Projectile

The distance (R) of a projectile can easily be calculated using the following simple algebraic formula, if a few complicating factors are ignored (e.g., wind speed, drag coefficient, etc.).

Figure: see image.

Suppose you could launch a projectile at a speed of 40 meters/second (about 90 miles per hour) and a launch angle of 25 degrees. How far down range (R) in meters could the projectile be hurled?

The solution for finding the down range distance of a projectile launched at a speed of 40 m/s and a launch angle of 25 degrees is shown here. Remember, that Angles are giving in degrees, so the degrees must first be converted to radians.

Figure: see image.

Be sure that you can work through the algebra and solve the equation with a calculator. Soon, you will turn it into an arithmetic expression in Java.

In programming pseudocode, the calculation would look something like this:

result = current_speed raised to the power of 2 * the sin of the angle in radians * 2 / gravitational constant

Be sure that the gravitational constant in the correct form for the unit of measure you are using.

Work out several answers with pencil, paper, and calculator first, before attempting to write the program. Pay close attention to units. The final units should be in meters.

Once you have it working as expected upload the .java file to this assignment drop box. You must also submit a Word doc or text file containing the Java code. Assignments not containing both the Java code and the text or Word file will be assigned a 0 for a grade.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.