Falling Bricks

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

The brick falls to the ground.

Falling Bricks

picture of falling brick

Gravity pulls upon the brick, causing it to go faster and faster. The distance between the brick and where it was released after t seconds is:

distance = (1/2)*G*t2
  • t is the number of seconds since the brick was released.
  • G is a constant: 9.80665
  • distance is in meters.

After 0.0 seconds, the brick has dropped 0.0 meters.

After 1.0 second, the brick has dropped (1/2) * 9.80665 * (1.0)2  =  0.5 * 9.80665 * 1.0 = 4.903325 meters.

After 2.0 seconds, the brick is has dropped (1/2)* 9.80665 * (2.0)2  =  0.5 * 9.80665 * 4.0  =  19.6133 meters.

After 3.0 seconds, the brick is has dropped (1/2)* 9.80665 * (3.0)2  =  0.5 * 9.80665 * 9.0  =  44.1299 meters.

This is getting tedious. Let's write a program that does the calculation for many values of t and prints the results as a table.

QUESTION 14:

Let's use a loop.

  • What is the loop control variable?
  • What does the loop body do?