I have recently begun studying UML. All is going fine so far until I saw the following:
This is a class Called Point2D It has 2 attributes which are x, type float and y, type float. It has 3 methods
- __init __(takes parameters 'x' and 'y', both of which are float) returns nothing
- distance (takes parameter 'target' which has the type class ???) returns a float
- display() returns nothing
I have no problem of reading these but my issue arose with the method 'distance', especially on how to interpret the parameter 'target' being Point2D
How should this be interpreted?
class Point2D: x = float y = float def display(self): print('coordinate x ' + str(self.x) + ', coordinate y ' + str(self.y)) def distance(self, target): gap = sqrt(abs(target.x-self.x)**2 + abs(target.y-self.y)**2) # target is still an enigma but the code above should describe what # distance is supposed to do def __init__(self, x, y): self.y = float(y) self.x = float(x)