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

I need to create a histogram for the following exercise Write a program that sti

ID: 3640688 • Letter: I

Question

I need to create a histogram for the following exercise

Write a program that stimulates a bouncing ball by computing its height in feet at each second as time passes on a simulated clock. At time zero, the ball begins at height zero and has an initial velocity supplied by the user. (An initial velocity of at least 100 feet per second is a good choice.) After each second, change the height by adding the current velocity; then subtract 32 from the velocity. If the new height is less than zero, multiply both the height and the velocity by -0.5 to simulate the bounce. Stop at the fifth bounce. The output from your program should have the following form:

Enter the initial velocity of the ball: 100
Time: 0 Height: 0.0
Time: 1 Height 100.0
Time: 2 Height 168.0
Time: 3 Height 204.0
Time: 4 Height 208.0
Time: 5 Height 180.0
Time: 6 Height 120.0
Time: 7 Height 28.0
Bounce !
Time: 8 Height 48.0

I already have the code that produces this output, however, Im not sure how create a histogram after each number is outputted. So I'd like to have some help on how to create a histogram based on my current java code. My teacher gave little to no details on how to create it. Please be as explanatory as possible because im fairly new to java and dont have too much experience yet.

Note: Im only trying to represent the height with asterisks

example:(output)

time 0, height 0  

time 1, height 10    **********

       time 2 height  15    ***************

 

public static void main(String[] args)
    {
     Scanner keyboard = new Scanner (System.in);
     double height = 0;
     int bounce = 0;
     int time = 0;
    
     System.out.println("Enter the initial velocity of the ball:");
     int velocity = keyboard.nextInt();
    
    
     while ( bounce < 5) {
     // displaying time and height
     System.out.println("time:" + time + " height:" + height);
    
     //updating time
     time++;
    
     // calculate new height
     height = height + velocity;
    
     // decrease velocity
     velocity = velocity - 32;
    
   
     if (height < 0)
     {
     // change velocity
        velocity *= -.5;
    
     // recalculate height
        height *= -.5;
     System.out.println("Bounce!");
     bounce++;

Explanation / Answer

I am not sure whether you mean just an asterisk height next to a number you provide. Then the code is dead simple ... while (bounce < 5) { // displaying time and height System.out.print("time:" + time + " height:" + height); printHeight((int) height/10); // updating time time++; ... private static void printHeight(int d) { for(int i = 0; i
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