Hi i m trying to design a program using object oriented approach.everything works perfect for me except the bounces.If the new height is less then 0 then multiply both the height and velocity by -0.5 to simulate the bounce.
import java.util.Scanner;
public class Ball11
{
public static void main (String [ ] args)
{
double height = 0;
int times = 0;
int speed=0;
int bounces=0;
int numOfBounces = 0;
Scanner scan= new Scanner (System.in);
System.out.println("Enter the initial velocity of the ball:");
height=scan.nextInt();
System.out.println("Enter the no of speed");
speed=scan.nextInt();
System.out.println("enter the no of bounces");
bounces=scan.nextInt();
System.out.println();
//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
do
{
times++;
height =height + speed;
speed-=32;
if (height > 0)
System.out.println ("time = " + times + " height = " + height + " speed = " + speed);
else
{
height = (double) (height * (-0.5));
speed = (int) (speed * (-0.5));
System.out.println ("bounce!");
System.out.println ("time = " + times + " height = " + height + " speed = " + speed );
break;
}
} while (true);
bounces++;
}
}