Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the best way to write this? Can i do it without a scanner class, but onl

ID: 3666562 • Letter: W

Question

What is the best way to write this? Can i do it without a scanner class, but only a bufferedreader?

This is a simple prototype program to predict the trajectory of a projectile under ideal conditions. You may assume that the projectile will have a constant velocity as it travels and that the only outside effect on the projectile will be due to the force of gravity. Thus the formula used to compute the time that it takes for the projectile to reach its target is:

The distance the projectile is off the ground at the target's distance is calculated using the formula:

You will receive the following information from the user:

projectile velocity (feet / sec)

angle of elevation (degrees)

distance from target (feet)

target size (height of target in feet)

elevation of target (to bottom of target in feet)

All values for one shot will be entered on one line of input. The program will continue reading input values until the user enters zeros for all values. Use the value of 32.17 as the constant for Gravity.

For each input set of values your program should indicates one of the following responses:

The target was hit by the projectile

The projectile was too low, height was: #.### feet

The projectile was too high, height was: #.### feet

The computed distance was too short to reach the target

This last message should be printed if the height was less then zero. The height should be printed using three digits to the right of the radix point. Example:

Error handling: If a calculation cannot be performed (ie: a divide by zero would occur) your program needs to alert the user using the message:

Explanation / Answer

Can help you with this:

import java.text.*;
import java.io.*;
public class projectile
{
public static void main (String argv []) throws IOException
{
double rads;
double time;
double height;
BufferedReader stdin =new BufferedReader (new InputStreamReader (System.in));
NumberFormat nf = NumberFormat.getNumberInstance ();
nf.setMaximumFractionDigits (3);
nf.setMinimumFractionDigits (3);
String [] strValues = stdin.readLine ().split ("\s+");
double velocity = Double.parseDouble (strValues [0]);
double angle = Double.parseDouble (strValues [1]);
double distance = Double.parseDouble (strValues [2]);
double size = Double.parseDouble (strValues [3]);
double elevation = Double.parseDouble (strValues [4]);
while (!done (velocity, angle, distance, size, elevation))
{
System.out.println ("The projectile's velocity is " + nf.format (velocity) + " feet per second");
System.out.println ("The angle of elevation is " + nf.format (angle) + " degrees");
System.out.println ("The distance to the target is " + nf.format (distance) + " feet");
System.out.println ("The target's size is " + nf.format (size) + " feet");
System.out.println ("The target is located " + nf.format (elevation) + " feet above the ground");
rads = toRads (angle);
if (Math.cos (rads) * velocity != 0.0)
{
time = getTime (velocity, rads, distance);
height = getHeight (velocity, rads, time);
if (height >= elevation && height <= elevation + size)
System.out.println ("The target was hit by the projectile");
else if (height >= 0 && height < elevation)
System.out.println ("The projectile was too low, height was: " + nf.format (height) + " feet");
else if (height >= elevation + size)
System.out.println ("The projectile was too high, height was: " + nf.format (height) + " feet");
else
System.out.println ("The computed distance was too short to reach the target");
}
else
System.out.println ("The computed distance cannot be calculated with the given data");
strValues = stdin.readLine ().split ("\s+");
velocity = Double.parseDouble (strValues [0]);
angle = Double.parseDouble (strValues [1]);
distance = Double.parseDouble (strValues [2]);
size = Double.parseDouble (strValues [3]);
elevation = Double.parseDouble (strValues [4]);
}
}
private static boolean done (double velocity, double angle, double distance, double size, double elevation)
{
return (velocity == 0.0 && angle == 0.0 && distance == 0.0 && size == 0.0 && elevation == 0.0);
}
private static double getTime (double velocity, double angleInRads, double distance)
{
return (distance / (velocity * Math.cos (angleInRads)));
}
private static double getHeight (double velocity, double angleInRads, double time)
{
return (velocity * time * Math.sin (angleInRads) - (32.17 * time * time) / 2.0);
}
private static double toRads (double angle)
{
return (angle * Math.PI / 180.0);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote