Write a method named fallingDistance that accepts an object%u2019s falling time
ID: 3538521 • Letter: W
Question
Write a method named fallingDistance that accepts an object%u2019s falling time (in seconds) as an argument. The method should return the distance (in meters) that the object has fallen during the given time interval.
Call your method to find out how far the object has fallen. Then determine if it has reached the ground. If it has not, tell me how far up in the air the object remains and how long it will take to get to the ground. If it is %u2018on%u2019 the ground, tell me it landed safely. If it has fallen farther than the height %u2013 tell me how far it is embedded in the dirt?
Use the formula: (use the Math function sqrt)
Explanation / Answer
import java.io.*; import java.util.*; class Fall { public static double fallingDistance(double t) { //D=(1/2)g(t^2) return (0.5*9.8*t*t); } public static void main(String args[]) throws IOException { Scanner s=new Scanner(System.in); System.out.println("Enter Falling Time of Object in seconds:"); double ft=s.nextDouble(); System.out.println("Enter Initial Height of Object in Metres:"); double ih=s.nextDouble(); double fallen=fallingDistance(ft); System.out.println("The object has fallen a distance of "+fallen+" metres."); if(fallen>=ih) { System.out.println("The object has reached the ground"); if(fallen>ih) System.out.println("The object is embedded "+(fallen-ih)+" metres in the dirt."); } else { System.out.println("The object has NOT reached the ground"); System.out.println("The object is "+(ih-fallen)+" metres above the ground"); double t= Math.sqrt((2.0*(ih-fallen)/9.8)); System.out.println("The object will take "+t+" seconds to reach ground"); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.