/** 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,
* .
* © 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
}
}
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10214
Categories:Programming Code Examples, Java/J2EE/J2ME, Basic Java
Tags:Java/J2EE/J2MEBasic Java
Post Data:2017-01-02 16:04:23
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada
