Question: 1 ) Make a UML Class Diagram for the Ball class demonstrated in the book Listing 1 4 . 3 and 1 4 . 4

1) Make a UML Class Diagram for the Ball class demonstrated in the book Listing 14.3 and 14.4
Listing 14.3
Adding an __init__() method
class Ball:
def __init__(self, color, size, direction):
self.color = color
self.size = size
self.direction = direction
def bounce(self):
if self.direction == "down":
self.direction ="up"
myBall = Ball("red", "small", "down")
print("I just created a ball.")
print("My ball is", myBall.size)
print("My ball is", myBall.color)
print("My ball's direction is ", myBall.direction)
print("Now I'm going to bounce the ball")
print()
myBall.bounce()
print("Now the ball's direction is", myBall.direction)
Listing 14.4
Using __str__() to change how the object prints
class Ball:
def __init__(self, color, size, direction):
self.color = color
self.size = size
self.direction = direction
def __str__(self):
msg ="Hi, I'm a "+ self.size +""+ self.color +" ball!"
return msg
myBall = Ball("red", "small", "down")
print(myBall)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!