/** Simulating dropping a ball from the top of the Washington * Monument. The program outputs the height of the ball each * second until the ball hits the ground. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class DropBall { public static void main(String[] args) { int time = 0; double start = 550.0, drop = 0.0; double height = start; while (height > 0) { System.out.println("After " + time + (time==1 ? " second, " : " seconds,") + "the ball is at " + height + " feet."); time++; drop = freeFall(time); height = start - drop; } System.out.println("Before " + time + " seconds could " + "expire, the ball hit the ground!"); } /** Calculate the distance in feet for an object in * free fall. */ public static double freeFall (float time) { // Gravitational constant is 32 feet per second squared return(16.0 * time * time); // 1/2 gt^2 } }