View the step-by-step solution to:


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 example


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.");}



Screen Shot 2019-09-30 at 10.37.55 PM.png

Screen Shot 2019-09-30 at 10.37.55 PM.png

You are NOT allowed to use iteration structures (loops) to code the repeated attempts.
The relevant part of the code that calculates and displays the trajectory results must be
copied four times into the program. Here is the pseudo-code version of the code you must
copy four times in your program:
if error positive
send overshoot message to the console
send undershot message to the console solicit new input for launch angle
calculate radian re-calculate all trajectory data
calculate error update minError compose output message display output message if absolute error less than 1
display hit on window
terminate the program Use the Math.abs( ) method to calculate the absolute value of the error, when you make a
decision about the accuracy of the shot. Set up a variable minError as suggested in the class description. Every time the program
generates a new error, update minError such that it stores the least absolute error occurred
this far. Use the Math.abs( ) and Math.min( ) methods for this purpose. Use the Math.sin() and Math.cos( ) methods for the sin and cosine functions. The first input for launch angle must be 45 degrees, you choose the four additional

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.


Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes