Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**************************************************************************************************** //This program computes the trajectory of a projectile. //Initial procedural oriented (unstructured) version. import java.util.*; // for Scanner public class unstructural { // constant

image text in transcribed

image text in transcribed

**************************************************************************************************** //This program computes the trajectory of a projectile. //Initial procedural oriented (unstructured) version.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago