Question: GIVEN PROGRAM: import java.util.*; // for Scanner public class unstructural { // constant for Earth acceleration in meters/second^2 public static final double ACCELERATION = -9.81;

 GIVEN PROGRAM: import java.util.*; // for Scanner public class unstructural {// constant for Earth acceleration in meters/second^2 public static final double ACCELERATION

GIVEN PROGRAM:

import java.util.*; // for Scanner

public class unstructural { // constant for Earth acceleration in meters/second^2 public static final double ACCELERATION = -9.81;

public static void main(String[] args) { Scanner console = new Scanner(System.in);

System.out.println("This program computes the"); System.out.println("trajectory of a projectile given"); System.out.println("its initial velocity and its"); System.out.println("angle relative to the horizontal."); System.out.println();

System.out.print("velocity (meters/second)? "); double velocity = console.nextDouble(); System.out.print("angle (degrees)? "); double angle = Math.toRadians(console.nextDouble()); System.out.print("number of steps to display? "); int steps = console.nextInt(); System.out.println();

double xVelocity = velocity * Math.cos(angle); double yVelocity = velocity * Math.sin(angle); double totalTime = - 2.0 * yVelocity / ACCELERATION; double timeIncrement = totalTime / steps; double xIncrement = xVelocity * timeIncrement;

double x = 0.0; double y = 0.0; double t = 0.0; System.out.println("step\tx(m)\ty(m)\ttime(sec)"); System.out.println("0\t0.0\t0.0\t0.0"); for (int i = 1; i

public static double round2(double n) { return (int) (n * 100.0 + 0.5) / 100.0; } }

Question 5 (20 points) Re-write the given procedural oriented (Unistructural) program to a functional (structural) oriented and an object-oriented program. You will need to submit two separate java programs (Functional and Object-oriented) for the question. This program calculates the trajectory that a projectile follows based on the user inputs of initial velocity and initial angle relative to the horizon. We will not get into the details of trajectory physics. This program computes the trajectory path it follows given Earth's gravity (9.81 m/sec2). The path distance (X, Y) is displayed based on the user entered number of steps. "What goes up must come down" - Isaac Newton. Ignoring the air- resistance, x-velocity does not change but y-velocity is subject to the gravity pull. This program displays the x, y distance and elapsed time based as the object goes up and comes back down. The y position changes based on the following physics equation: y-distance = y Velocity * time + 0.5 * ACCELERATION ***t. x-distance = xVelocity * timelncrement; timelncrement = totalTime / steps (user input). For this problem, you don't have to get into the physics details. Download the given program (unstructural.java) and run it: This program computes the trajectory of a projectile given its initial velocity and its angle relative to the horizontal. velocity (meters/second)? 300 angle (degrees)? 45 number of steps to display? 10 step y (m) 0.0 x(m) 0.0 917.43 1834.86 2752.29 3669.72 4587.16 5504.59 6422.02 7339.45 8256.88 9174.31 825.69 1467.89 1926.61 2201.83 2293.58 2201.83 1926.61 1467.89 825.69 0.0 time (sec) 0.0 4.32 8.65 12.97 17.3 21.62 25.95 30.27 34.6 38.92 43.25 10 Go over the given program (Procedural) and modify the areas to make it functional based. After completing the functional based version, create another java program using an object-oriented approach

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!