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

Below is the code for a Ball class, which illustrate the bouncing of the balls i

ID: 3857946 • Letter: B

Question

Below is the code for a Ball class, which illustrate the bouncing of the balls in X and Y coordinates.

class Ball:

def __init__ (self, x, y, vx, vy):

self.xPos = x

self.yPos = y

self.xVec = vx

self.yVec = vy

def getXPos(self):

return self.xPos

def getYPos(self):

return self.yPos

def getXVel(self):

return self.xVel

def getYVel(self):

return self.yVel

def advance(self, timestep=1):

self.xPos += self.xVel *timestep

self.yPos += self.yVel *timestep

Write a bounce method for the class that multiplies both the y-coordinate

and y-velocity by -1.

Explanation / Answer

The answer is as follows:

def bounce(self):
    self.yPos = self.yPos* (-1)
    self.yVel = self.yVel * (-1)

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