Created
March 17, 2015 14:41
-
-
Save ashishdasnurkar/3a60ac462887d268bc11 to your computer and use it in GitHub Desktop.
Define 3 python classes. Dot, Line and Rectangle. Dot has coordinates x and y. Line has 2 Dots and Rectangle has 4 Lines. Rectangle has method named "get_dots" that prints coordinates of all its Dots into standard output. Instantiate all the classes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Define 3 python classes. Dot, Line and Rectangle. Dot has coordinates x and y. Line has 2 Dots and Rectangle has 4 Lines. Rectangle has method named "get_dots" that prints coordinates of all its Dots into standard output. Instantiate all the classes. | |
''' | |
class Dot(object): | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
def __str__(self): | |
return '(%s, %s)' % (self.x , self.y) | |
class Line(object): | |
def __init__(self, start, end): | |
self.start = start | |
self.end = end | |
def __str__(self): | |
return '%s : %s' % (self.start,self.end) | |
class Rectangle: | |
def __init__(self, top, right, bottom, left): | |
self.top = top | |
self.right = right | |
self.bottom = bottom | |
self.left = left | |
def get_dots(self): | |
print self.top, self.right, self.bottom, self.left | |
topStart = Dot(0,0) | |
topEnd = Dot(100, 0) | |
topLine = Line(topStart, topEnd) | |
rightStart = Dot(100,0) | |
rightEnd = Dot(100, 100) | |
rightLine = Line(rightStart, rightEnd) | |
bottomStart = Dot(100,100) | |
bottomEnd = Dot(0, 100) | |
bottomLine = Line(bottomStart, bottomEnd) | |
leftStart = Dot(0,100) | |
leftEnd = Dot(0, 0) | |
leftLine = Line(leftStart, leftEnd) | |
rect = Rectangle(topLine, rightLine, bottomLine, leftLine) | |
rect.get_dots() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment