Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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. package com.Spring2020. AS1; 7/This program computes the trajectory of a projectile.. import java.util.*; // for Scanner public class unstructural { 11 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 y Velocity = 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("\te.\te.\te."); for (int i = 1; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started