CS 1401 Assignment #5

Date Assigned: Wednesday, February 16, 2005

Due Date: Wednesday, February 23, 2005, before the beginning of your lab section.

Goals: to learn mathematical functions like sin(x), conditions, and logical expressions.

Points: This assignment is worth a total of 20 points. No late assignments will be accepted, but credit will be given for partially completed assignments turned in on time.

Assignment: To celebrate the good grades of CS 1401 students, the Department of Computer Science decided to launch some fireworks. To avoid accidents, the department decided to design a software tool that would compute the trajectory of each launched rocket.

This tool uses the following formulas. Let us design a coordinate system XY in such a way that the launcher is located at the center of this coordinate system, i.e., at a point with coordinates (0,0), the X axis is horizontal, and the Y axis is vertical.

For each rocket, we know the velocity V0 (in feet per second) with which it starts moving, and we set up an angle A (in degrees) at which this rocket is shot. The angle should be between 0 and 90 degrees: 0 degrees means that we shoot the rocket parallel to the earth; 90 degrees means that we shoot the rocket straight into the sky. Let g = 9.8 m/sec^2 be the free-fall acceleration.

Once we know the initial velocity and the angle, we can compute the horizontal and vertical components of this velocity as VX_0 = V0*cos(A) and VY_0 = V0*sin(A). Then, once someone wants to find the position and velocity of the rocket at some moment of time t, this person can use the following formulas:

Structure: Define a class CurrentState in which each object (state) is characterized by two coordinates and two velocity components. Make sure that your description includes:

Define a class Rocket in which each rocket is characterized by its initial velocity (in feet per second) and angle (in degrees). This class should include the following value-returning methods:

Named constants such as g and named constants that are needed for converting from degrees to radians and from meters to feet should be defined in the class Rocket.

All readings from the user and all printing to the screen should be in the main method of the application class.

The application class should do the following:

Example. Let us assume that we launch the rocket with velocity V0 = 30 feet/sec, at an angle of 60 degrees. Then, we do the following preliminary computations.

Now, if the user asks for the state of the rocket at a time t = - 1.0 sec, since this time is negative, the answer should be: the rocket's coordinates are X = 0 and Y = 0, and its velocity components are VX = 0 and VY = 0.

If the user asks for the state of the rocket at a time t = 1.5 sec, then

V_Y0*t - (1/2)*g*t^2 = 25.980762*1.5 - (1/2)*32.152231*1.5^2 =
38.971143 - 36.1712259 = 2.799884
is non-negative. So:

If the user asks for the state of the rocket at a time t = 2.0 sec, then

V_Y0*t - (1/2)*g*t^2 = 25.980762*2.0 - (1/2)*32.152231*2.0^2 =
51.961524 - 64.304462
is negative, which means that the rocket has alreaxdy landed. In this case, we compute the moment t0 = 2*(VY_0/g) when it landed as
t0 = 2*(25.980762/32.152231) = 2*0.8080547 = 1.6161094 sec.
In this case:

Deliverables: as announced in the labs and explained in the handouts given to you in the labs.