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);

 }
}
hiddepolen commented: Homework question -1

Recommended Answers

All 2 Replies

you mean: can we re-write it for you in OO-design?
sure we can, but we won't.

what you've done so far, is copy pasting your assignment here, and hoping we will do your work for you.

step 1: decide on which objects you'll need
step 2: implement the methods you need
...

Thread closed!
Please follow further discussion here

@ali11 creating multiple entries with same question is unwelcome practice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.