Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me write code for this program in java. mine keep on showing errors When an object is falling because of gravity, the following
please help me write code for this program in java. mine keep on showing errors
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 gt? Where d = distance in meters, g = gravity and t = time in seconds. Use 9.8 m/s for gravity Write a method computeFalling Distance 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 computeFalling Distance (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 computeFalling Distance for each integer. Ex: If the input is: 3 the output is: ee ENG INTI 12 the output is Time 1 Distance 4.90 19.60 44.10 2 3 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("%.2f ", yourValue); 289734 1726976 LAB ACTIVITY 5.19.1: LABA: Falling distance 0/10 LabProgram.java Load default template 1 import java.util.Scanner; 2 3 public class LabProgram! 4 public class fallingDistance 5 public static double fallingDistance (double t){ ENG LabProgram.java Load default template... 5 6 7 8 9 10 11 public static double fallingDistance (double t){ double d,v,8=9.85; d=0.5*g* (t*t); return d; } 12} 13 14 15 16 17 18 19 20 21 22 23 24 25 public static void main(String args[]){ Scanner scnr = new Scanner(System.in); double t; System.out.println(" Enter Amount of time in seconds: " + "sec"); t-scan.nextDouble(); fallingDistance(t); for(int i=1; i Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box then click Run program and observe the program's output in the ENG 7:00 INTL 1/21/24 here to search O (99
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