class Cannonball { double x; double y; double vx; double vy; final double g = 9.81; double max; Cannonball(double speed, double angle) { System.out.println("A cannonball with initial velocity " + speed + "m/s launched at an angle of " + Math.toDegrees(angle) + " degrees."); x = 0; y = 0; vx = Math.cos(angle) * speed; vy = Math.sin(angle) * speed; max = 0; } void move() { double deltaT = 0.01; x += vx * deltaT; y += vy * deltaT; vy -= g * deltaT; if (y > max) { max = y; } } void report() { System.out.print("Located at: (" + x + ", " + y + ") "); System.out.println(" ... max altitude so far: " + max); } double height() { return y; } } class Max { public static void main(String[] args) { Cannonball c = new Cannonball(10, Math.PI / 4); for (int i = 0; i < 10 * 100; i++) { // flying 10 seconds c.move(); System.out.print( i / 100.0 + " seconds into the flight: "); c.report(); if (c.height() < 0) { System.out.println("The cannonball landed!"); break; } } } }