Java Concepts exercise 6.4 pg. 232 -Write a Java program to simulate the physics
ID: 3869058 • Letter: J
Question
Java Concepts exercise 6.4 pg. 232 -Write a Java program to simulate the physics of a cannonball flight-
Suppose a cannonball is propelled vertically into the air with a starting velocity v0. Any calculus book will tell us that the position of the ball after t seconds is s(t) = -0.5 * g * t2 + v0 * t, where g = 9.81 m/sec2 is the gravitational force of the earth.
1) In our simulation, we will consider how the ball moves in very short time intervals deltaT. In a short time interval the velocity v is nearly constant, and we can computer the distance the ball moves as deltaS = v. In our program, we will simply set double deltaT = 0.01 and update the position by s = s + v * deltaT. In a short time interval, v decreases by g * deltaT, and we must keep the velocity updated as v = v - g * deltaT.
2) In the next iteration the new velocity is used to update the distance. Now run the simulation until the cannonball falls back to the earth. Get the initial velocity as an input (100 m/sec is a good value). Update the position and velocity 100 times per second, but only print out the position every full second. Use a class Cannonball and a CannonballTest class.
3) Important: be sure to handle for illegal arguments with exceptions.
You can assume an initial angle of 45 degrees or ask the user to input an angle.
Explanation / Answer
frilled.cs.indiana.edu%cat Three.java class Three { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); String line; do { System.out.print("Type something: "); line = c.readLine(); System.out.println("You typed: " + line); } while (! line.equals("bye")); System.out.println("Good bye!"); } } class Wow { public static void main(String[] args) { int x = 1; if (x > 2) ; { System.out.println("Yes, " + x + " is greater than 2."); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.