Create a Ball class that will represent balls on a pool table. The data for this object will be the ball themselves. Her

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Create a Ball class that will represent balls on a pool table. The data for this object will be the ball themselves. Her

Post by answerhappygod »

Create a Ball class that will represent balls on a pool table.
The data for this object will be the ball themselves. Here are the
Functions that need to be implemented along with the class itself
and some of the point distributions (note that the pool table is
described as a 1 by 2 playing area and thus the ball should not be
out of bounds for any reason.):
(12pts) total:
(4pts) Ball class:
Instance Vars:
(1pt) number: this will be an integer
that will represent the number of a ball
(1pt) color: this will be a string that
will represent the color of the ball
(1pt) isStriped: this will be a Boolean
that will describe if the ball is striped or not
(1pt) location: this will be a pair of
numbers that will represent the coordinate of the balls center
location on the pool table.
One way to implement this is with two floats (just call them
loc1 and loc2), a list with two numbers or, if you're feeling
fancy, try utilizing a tuple
(https://www.w3schools.com/python/python_tuples.asp). The
coordinates should not go beyond the hundredths place. Make sure
that when the ball location is instantiated, that the ball is
within a 1 by 2 region. If the coordinates given are not with this
range, set the location to (0.5, 0.5).
Two methods:
(2pts) Distance: Find the distance of a ball to the
coordinates given (try using distance formula, or sqrt((y1-y2)^2 +
(x1-x2)^2)
(1pts) setLocation: Set the location of a ball to the
coordinates given. This function should also check if the
coordinates given are out of bounds or not and do nothing if the
given coordinates are.
(1pt) below your class, show that the class works by printing
out the 9 ball and all of its attributes (set the balls location to
(0.5, 0.5) when initializing the ball). Introduce the 7 ball and
print out the 7 ball's attributes (again set the balls location to
(0.5, 0.5) when initializing the ball). Use the set location to set
the coordinates of the 9 ball to (1,2) and the location of the 7
ball to (3,4) (this is for out of bounds to test error
checking) Then print out the distance of these two balls.
Create some code that will impement your newly created ball
object. For reference, use the following locations for the six
holes of the pool table (holes =
[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)]) Here are the Functions that
need to be implemented along with the class itself and some of the
point distributions:
(4pts)
(1pt) randomize all ball locations (try using
math.random and remember to keep coordinates to the hundreths
place)
(1pt) print location of all balls
(1pt) distance to closest ball from ball 9
(1pt) distance to closest hole from ball 9
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply