Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A standard science experiment is to drop a ball and see how high it bounces. Onc

ID: 3790813 • Letter: A

Question

A standard science experiment is to drop a ball and see how high it bounces. Once the "bounciness" of the ball has been determined, the ratio gives a bounciness index. For example, if a ball dropped from a height of 10 feet bounces 6 feet high, the index is 0.6, and the total distance traveled by the ball is 16 feet after one bounce. If the ball were to continue bouncing, the distance after two bounces would be 10 ft + 6 ft + 6 ft + 3.6 ft = 25.6 ft. Note that the distance traveled for each successive bounce is the distance to the floor plus 0.6 of that distance as the ball comes back up. Write a program that lets the user enter the initial height of the ball and the number of times the ball is allowed to continue bouncing. Output should be the total distance traveled by the ball.

Explanation / Answer

import java.util.Scanner;

public class BouncingBall {

   public static void main(String[] args) {
       // Declaring variables
       double initial_ht, distance_travelled = 0.0;
       int no_of_bounces;
       double tot = 0.0,first_bounce;
       // Scanner object is used to get the inputs entered by the user
       Scanner sc = new Scanner(System.in);

       // Getting the initial height entered by the user
       System.out.print("Enter Initial Height (ft):");
       initial_ht = sc.nextDouble();

       // Getting the no of bounces entered by the user
       System.out.print("Enter No of bounces :");
       no_of_bounces = sc.nextInt();

   //Calculating the distance travelled in first bounce
       first_bounce=initial_ht+initial_ht*0.6;
      
       for (int i = 1; i < no_of_bounces; i++) {
           tot+=first_bounce;

           first_bounce=first_bounce*0.6;
       }

       System.out.println("Distance Travelled (ft):" + (first_bounce + tot));

   }

}

___________________

Output:

Enter Initial Height (ft):10
Enter No of bounces :4
Distance Travelled (ft):34.816

___________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote