Notice that this class extends GOval. This means that all of the methods from the GOval class are available to be used with the ball.
In MainClass.java:
Create a new Ball object. Do this in the run() method. There is already an instance variable called “ball”; initialize that variable in the run() method, by creating a new Ball object. DON’T create another ball variable for now (unless you want your game to have more than one ball object).
We advice that you change the type of the ball to GOval instead of Ball.
Create a method called randomFood(). In this method, you should set the location of the ball to a random x and random y. This method needs to make sure that the ball isn’t placed outside of the canvas. Hint: You can use setLocation() from the GOval class.
Make sure to add the ball to the canvas once it’s positioned correctly.