-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adeyin Ikpah
committed
May 26, 2020
1 parent
08912e4
commit 2137d2a
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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()) |
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
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 | ||
|
||
|
||
|
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
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() |
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
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) |