Home / Expert Answers / Computer Science / take-a-look-at-the-bouncing-ball-javafx-example-https-liveexample-pearsoncmg-com-html-ballpane-h-pa850

(Solved): Take a look at the Bouncing Ball JavaFX example: https://liveexample.pearsoncmg.com/html/BallPane.h ...



Take a look at the Bouncing Ball JavaFX example:

https://liveexample.pearsoncmg.com/html/BallPane.htmlLinks to an external site.

https://liveexample.pearsoncmg.com/html/BounceBallControl.htmlLinks to an external site.

Change the program in an Object Oriented way to handle 20 bouncing balls instead of just one.

Notice that for each ball you need:

1. It's center x,y location

2. It's radius

3. It's color

4. It's direction of motion (dx, dy)

Also notice that the JavaFX Circle class already has the information listed in the first 3 items above. So you can create a Ball class that has a Circle in it, PLUS the direction of motion for that ball (dx,dy).

Should it ball have a Move method? or is it best to leave the move method out of the Ball class?



We have an Answer from Expert

View Expert Answer

Expert Answer



The move method should ideally be a part of the Ball class. In this manner, the Ball object itself takes on the role of moving the ball. Encapsulating an object's behaviour into the object itself is a desirable object-oriented practise.
Here is an example implementation of the Ball class that includes a move method:




We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe