explain the codes below in details: % request the user to input the desired option with regard the unit % if the user input is ‘MKS’, then the units will be in meters and seconds % If the user input is ‘FPS’, then the units will be in feet and seconds unit = input("Please choose a unit: MKS (meters and seconds) or FPS (feet and seconds): ", "s");   % conditional statements enable you to select at run time which block of code to execute % in the situation where the user has input “MKS” if (unit == "MKS" || unit == "mks") % gravity is equivalent to -9.81 gravity = -9.81; % in the situation where the user has input “FPS”

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 11PE
icon
Related questions
icon
Concept explainers
Question

Please explain the codes below in details:

% request the user to input the desired option with regard the unit
% if the user input is ‘MKS’, then the units will be in meters and seconds
% If the user input is ‘FPS’, then the units will be in feet and seconds
unit = input("Please choose a unit: MKS (meters and seconds) or FPS (feet and seconds): ", "s");
 
% conditional statements enable you to select at run time which block of code to execute
% in the situation where the user has input “MKS”
if (unit == "MKS" || unit == "mks")
% gravity is equivalent to -9.81
gravity = -9.81;
% in the situation where the user has input “FPS”
elseif (unit == "FPS" || unit == "fps")
% gravity is equivalent to -32.174
gravity = -32.174;
else
% in the situation where the user has input none of the provided options
error = " Please enter an input only within the provided options ";
% disp( ) displays the value of variable without printing the variable name
% display error
disp(error)
% return control to the invoking program before it reaches the end of the script or function
return
% to terminate statements
end
% for the variables needed in accordance with the formula
% request the user to input the desired value for the magnitude of the initial velocity
Vo = input("Enter magnitude of the initial velocity: ");
% request the user to input the desired value for the angle
theta = input("Enter angle: ");
% request the user to input the desired value for the height
h = input("Enter height: ");
% request the user to input the desired value for the acceleration
ax = input("Enter acceleration: ");
 
% mathematical formula equations
% formula equation for time
time = (Vo.*sind(theta) + sqrt((Vo.*sind(theta)).^2-2*gravity*h)) / (-gravity);
t = linspace(0,time);
 
% formula equation for velocity (x)
velocityx = Vo*(cosd(theta));
 
% formula equation for velocity (y)
velocityy = Vo*(sind(theta));
 
% formula equation for displacement (x)
displacementx = (velocityx.*t) + ((1/2)*ax*(t.^2));
 
% formula equation for displacement (y)
displacementy = (velocityy.*t) + ((1/2)*gravity*(t.^2));
 
% formula equation for final velocity (x)
finalvelocityx = sqrt(velocityx.^2 + 2*ax*displacementx);
 
% formula equation for final velocity (y)
finalvelocityy = sqrt(velocityy.^2 + 2*gravity*displacementy);
 
% formula equation for magnitude
magnitude = sqrt((finalvelocityx.^2)+(finalvelocityy.^2));
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning