Skip to content

Commit

Permalink
Adding shape and polygon classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeyin Ikpah committed May 26, 2020
1 parent 08912e4 commit 2137d2a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions shape/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from shape.square import Square
from shape.triangle import Triangle
"""Import the file_location.filename and class.
This need to import square and triangle to run.
Everything will be run from the main class.
"""

s1 = Square()
"""Call an instance of the square class"""
s1.set_value(8, 54)
"""Set the values of the square"""
print(s1.get_area())
"""print the area"""


s2 = Triangle()
"""Call an instance of the triangle class"""
s2.set_value(35, 89)
print(s2.get_tri_area())
21 changes: 21 additions & 0 deletions shape/polygon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is the main class that the others import
class Polygon:
"""declare private variables, there is no constructor(__init__)"""
__width = None
__height = None

def set_value(self, width, height):
""" Set the private variables width and height of the shape"""
self.__width = width
self.__height = height

def get_width(self):
""" Use getter to get width. Need to do this because it is private"""
return self.__width

def get_height(self):
""" Use getter to get height. Need to do this because it is private"""
return self.__height



9 changes: 9 additions & 0 deletions shape/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from shape.polygon import Polygon
"""Import the file_location.filename and class"""


class Square(Polygon):
"""returns area of a square
Inheritance (Inherits all the variables for the Polygon class)"""
def get_area(self):
return self.get_width() * self.get_height()
9 changes: 9 additions & 0 deletions shape/triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from shape.polygon import Polygon
"""Import the file_location.filename and class"""


class Triangle(Polygon):
"""returns area of a triangle
Inheritance (Inherits all the variables for the Polygon class)"""
def get_tri_area(self):
return int(self.get_width() * self.get_height() * 0.5)

0 comments on commit 2137d2a

Please sign in to comment.