Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started