Here's the explanation of the problem:
PROBLEM:
OTHER STIPULATIONS (Made by Professor):When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period:
d = 1/2gt2
The variables in the formula are as follows:
-"d" is the distance in meters
-"g" is 9.8
-"t" is the amount of time (in seconds) that the object has been falling
Write a method named fallingDistance that accepts an object's falling time (in seconds) as an argument. The method should return the distance (in meters) that the object has fallen during that time interval. Demonstrate the method by calling it in a loop that passes the values 1 through 10 as arguments, and displays the return value.
And this is the sample Display Output we're suppose to have:-Instead of 9.8, make g = 9.80665
-Make "g" a named constant, and declare it locally inside fallingDistance.
OUTPUT:
output2.png
But, I got this..............
output.png
Lastly, here's my Java program that definitely needs some tweaking:
import java.text.DecimalFormat; public class fallingDistance { public static void main(String[] args) { int fallingTime = 0; String name1 = "Time", name2 = "Distance"; String name3 = "(seconds)", name4 = "(meters)"; DecimalFormat num = new DecimalFormat("#,###.00"); System.out.println("Falling Distance\n"); System.out.printf("%s %15s\n", name1, name2); System.out.printf("%s %10s\n", name3, name4); System.out.println(); for(int i = 1; i <= 10; i++) { fallingTime++; if(fallingTime > 1) { System.out.println(fallingTime + " " + num.format(fallingDistance(i))); } } } public static double fallingDistance(double fallingTime) { double g = 9.80665, a = 0.5; double d = a * g * Math.pow(fallingTime,2); return d; } }
I'll fix the spacing, making g constant, and all the little stuff. Just need help with the following:
NEED TO:
PLEASE HELP ME! Thanks!1) include the 1 and 4.90. It's not showing up for some reason, and don't know exactly how to put it in there.
2) Get the decimal points lined up.