Question: JAVA 5.19 LAB^: Falling distance When an object is falling because of gravity, the following formula determines the distance the object falls in a specific

JAVA

5.19 LAB^: Falling distance

When an object is falling because of gravity, the following formula determines the distance the object falls in a specific time period:

d = 1/2 gt2

Where d = distance in meters, g = gravity and t = time in seconds. Use 9.8 m/s for gravity.

Write a method computeFallingDistance() that has one parameter: the falling time (in seconds) of an object. The function returns the distance (in meters) the object has fallen.

Input Validation: If the parameter is negative or zero, the function returns 0.

Ex: If the method is called with the given arguments, will return the following distances:

computeFallingDistance(1) returns 4.9 computeFallingDistance(2) returns 19.6 computeFallingDistance(3) returns 44.1 computeFallingDistance(10) returns 490.0 

Next, in main, prompt the user for an integer time. The program should loop from 1 to the user input (inclusive), calling computeFallingDistance for each integer. Ex: If the input is:

3 

the output is:

Time Distance 1 4.90 2 19.60 3 44.10 

Output the floating-point numbers with 2 digits after the decimal point. Your decimal points should align and the numbers should be right-aligned under Distance (as above). This can be achived as follows: System.out.printf("%8.2f ", yourValue);

starting out code is:

import java.util.Scanner;

public class LabProgram { /* Type your method here. */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here */

} }

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!