-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise17_10.py
48 lines (33 loc) · 1.01 KB
/
Exercise17_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Point:
""" Point class for representing and manipulating x,y coordinates. """
def __init__(self, initX, initY):
self.x = initX
self.y = initY
def getX(self):
return self.x
def getY(self):
return self.y
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y)
class Rectangle:
"""Rectangle class using Point, width and height"""
def __init__(self, initP, initW, initH):
self.location = initP
self.width = initW
self.height = initH
def getwidth(self):
return self.width
def getheight(self):
return self.height
def area(self):
return self.width * self.height
def perimeter(self):
return (self.width * 2) + (self.height * 2)
def __str__(self):
return "width=" + str(self.width) + ", height=" + str(self.height)
loc = Point(4, 5)
r = Rectangle(loc, 10, 5)
print(r)
print (r.getheight())
print (r.area())
print (r.perimeter())