Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago