Re-design the program using the object-oriented approach
- Allow the user to play the ball as many times as he wants and each time he can decide the initial ball speed and the number of bounces to stop the ball
here is what i did before.
import java.util.Scanner;
public class Ball
{
public static void main (String [ ] args)
{
double height = 0;
int times = 0;
int x=0;
int numOfBounces = 0;
Scanner scan= new Scanner (System.in);
System.out.println("Enter the initial velocity of the ball:");
x=scan.nextInt();
System.out.println();
System.out.println ("time = " + times + " height = " + height);
do
{
do
{
times++;
height =height + x;
x-=32;
if (height > 0)
System.out.println ("time = " + times + " height = " + height);
else
{
height = (double) (height * (-0.5));
x = (int) (x * (-0.5));
System.out.println ("bounce!");
System.out.println ("time = " + times + " height = " + height );
break;
}
} while (true);
numOfBounces++;
} while (numOfBounces < 5);
System.exit (0);
}
}