Question: 1 ) Make a UML Class Diagram for the Ball class demonstrated in the book Listing 1 4 . 3 and 1 4 . 4
Make a UML Class Diagram for the Ball class demonstrated in the book Listing and
Listing
Adding an init method
class Ball:
def initself color, size, direction:
self.color color
self.size size
self.direction direction
def bounceself:
if self.direction "down":
self.direction up
myBall Ballred "small", "down"
printI just created a ball."
printMy ball is myBall.size
printMy ball is myBall.color
printMy ball's direction is myBall.direction
printNow Im going to bounce the ball"
print
myBall.bounce
printNow the ball's direction is myBall.direction
Listing
Using str to change how the object prints
class Ball:
def initself color, size, direction:
self.color color
self.size size
self.direction direction
def strself:
msg Hi Im a self.size self.color ball!"
return msg
myBall Ballred "small", "down"
printmyBall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
