Answered step by step
Verified Expert Solution
Link Copied!

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

Students also viewed these Databases questions