// Simulates the dropping of two balls from various heights. import java.awt.*; public class Balls { public final static int PANEL_HEIGHT = 600; public final static int PANEL_WIDTH = 600; public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(PANEL_WIDTH, PANEL_HEIGHT); Graphics g = panel.getGraphics(); int ball1x = 100, initialBall1y = 600, v01 = 25; int ball2x = 200, initialBall2y = 500, v02 = 15; // draw the balls at each time increment for (double t = 0; t <= 10.0; t += 0.1) { double height1 = initialBall1y - displacement(v01, 9.81, t); g.fillOval(ball1x, PANEL_HEIGHT - (int)height1, 10, 10); double height2 = initialBall2y - displacement(v02, 9.81, t); g.fillOval(ball2x, PANEL_HEIGHT - (int)height2, 10, 10); panel.sleep(50); // pause for 50 ms panel.clear(); } } public static double displacement(double v0, double a, double t) { return v0 * t + 0.5 * a * Math.pow(t, 2); } }