-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabExam01.java
39 lines (36 loc) · 946 Bytes
/
LabExam01.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Created by Noah Shaw
*/
import java.util.Scanner;
public class LabExam01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to the bouncing ball program!");
System.out.println("");
System.out.println("Please enter the initial velocity.");
Scanner keyboard = new Scanner(System.in);
double initialVelocity = keyboard.nextDouble();
int time = 0;
double height = 0;
int bounces = 0;
System.out.println("Time: "+time+" Height: "+height);
while(height>=0)
{
time++;
height = height + initialVelocity;
initialVelocity = initialVelocity - 32;
if(height<0)
{
height = height * (-0.5);
initialVelocity = initialVelocity * (-0.5);
System.out.println("BOUNCE!");
bounces++;
if(bounces==5)
{
System.exit(0);
}
}
System.out.println("Time: "+time+" Height: "+height);
}
}
}