Question

# I am trying to figure out how to complete the code. I have gotten most of it other than these repeated attempts in

the code. I'm not suppose to use loops and am trying to figure out how to code it.** I don't need this done for me but rather looking for an example as to how code something like this. For instance It says in the question to solicit a new input and to recalculate. How would I code something like that? Again I don't really need the answer to my code but rather an examp**l**e**

CODE::

**package** project_01_practice;

**import** javax.swing.JOptionPane;

**public** **class** ProjectileMotion {

**public** **static** **void** main(String[] args) {

// **TODO** Auto-generated method stub

String task, task1, title;

**final** **int** Gravitation = 32;

**final** **double** distanceToTarget;

// to store the distance to the target in feet

**double** initialVelocity;

// the projectiles initial velocity shown in feet per second

**double** launchAngle;

//storing the current input for the launch angle in degrees

**double** radian;

// the stored angle displayed in radians

**double** flightTime;

//store the flight time of the projectile as defined by formula 1 in the description

**double** highestPoint;

// store the highest point that the projectile reaches

**double** distanceTraveled;

// store the distance traveled by the projectile

**double** error;

// store difference between distance traveled and distance to the target

**double** minError = 0;

//store the least absolute error

**double** closestDistance = Double.** MAX_VALUE**;

String trajectory;

task = "Enter Target distance into feet:";

title = "Request an Input";

distanceToTarget = Double.*parseDouble*(JOptionPane.*showInputDialog*(**null**, task, title, JOptionPane.** OK_CANCEL_OPTION**));

task = "Enter initial velocity in feet/sec:";

title = "Request an Input";

initialVelocity = Double.*parseDouble*(JOptionPane.*showInputDialog*(**null**, task, title, JOptionPane.** QUESTION_MESSAGE**));

task = "Enter Launch Angle in Degrees:";

launchAngle = Double.*parseDouble*(JOptionPane.*showInputDialog*(**null**, task, title, JOptionPane.** OK_CANCEL_OPTION**));

//Math equations being used

radian = launchAngle * Math.** PI** / 180;

flightTime = (2 * initialVelocity * Math.*sin*(radian)/Gravitation);

highestPoint = (initialVelocity * Math.*sin*(radian) * (flightTime) - 0.5 * Gravitation * Math.*pow*(flightTime, minError));

distanceTraveled = initialVelocity * Math.*cos*(radian) * (flightTime);

error = distanceTraveled - distanceToTarget;

minError = Math.*abs*(error);

trajectory = String.*format*("initial velocity: %.2f feet/secondn " +

"Launch Angle : %.2f degreesn" +

"Flight Time: %.2f secondsn" +

"Maximum Height: %.2f feetn" + "distance traveled: %.2f feetn" + "target missed by: %.2f feetn",

initialVelocity, launchAngle, flightTime, error, distanceTraveled, highestPoint);

JOptionPane.*showMessageDialog*(**null**, "initial velocity: " + initialVelocity + "nlaunch angle: " + launchAngle + "nflight time: " +

flightTime + "nhighest point: " + highestPoint + "ndistance traveled: " + distanceTraveled + "ntarget missed by: " + (distanceTraveled - radian) + " feet");

//Calculating if the error is below zero or over 45 degrees and if so fix the launch angle

**if** (error > 0)

{ System.** out**.println("Shot went beyond the target. Decrease the launch angle.");}

**else** **if** (error < 45)

{ System.** out**.println("Shot went beyond the target. Increase the launch angle.");}

}

}

### Recently Asked Questions

- I need help solving this... For the following array 30 40 20 15 60 80 75 4 20 show the new array after each pass of insertion sort and selection sort. How many

- 1.Code the Rock Paper Scissors program: a.Get a move choice from playerA which must be R, P, S or r, p, s Loop until you get a valid move b.Get a move choice

- In unit 6 we are introduced to the concept of polymorphism which is derived from the Greek words poly, which means many and morpheus, which means form,