In: Computer Science
Create a generic superclass Shoe, which has at least 3 subclasses with attributes as shown below: class Shoe: Attributes: self.color, self.brand class Converse (Shoe): # Inherits from Shoe Attributes: self.lowOrHighTop, self.tongueColor, self.brand = "Converse" class CombatBoot (Shoe): # Inherits from Shoe Attributes: self.militaryBranch, self.DesertOrJungle class Sandal (Shoe): # Inherits from Shoe Attributes: self.openOrClosedToe, self.waterproof Implement the classes in Python. Create a separate test module where 2 instances of each subclass are created. Test the methods by displaying their information.
(*Note: Please up-vote. If any doubt, please let me know in the comments)
CODE (Classes):
class Shoe:
def __init__(self,color,brand):
self.color = color
self.brand = brand
def __str__(self):
return f"Color: {self.color}, Brand: {self.brand}"
class Converse (Shoe): # Inherits from Shoe Attributes:
def __init__(self,color,lowOrHighTop,tongueColor):
Shoe.__init__(self,color,"Converse")
self.lowOrHighTop = lowOrHighTop
self.tongueColor = tongueColor
def __str__(self):
return f"{Shoe.__str__(self)}, Top: {self.lowOrHighTop}, Tongue color: {self.tongueColor}"
class CombatBoot (Shoe): # Inherits from Shoe Attributes:
def __init__(self,color,brand, militaryBranch,DesertOrJungle):
Shoe.__init__(self,color,brand)
self.militaryBranch = militaryBranch
self.DesertOrJungle = DesertOrJungle
def __str__(self):
return f"{Shoe.__str__(self)}, militaryBranch: {self.militaryBranch}, DesertOrJungle: {self.DesertOrJungle}"
class Sandal (Shoe): # Inherits from Shoe
def __init__(self,color,brand,openOrClosedToe,waterproof):
Shoe.__init__(self,color,brand)
self.openOrClosedToe = openOrClosedToe
self.waterproof = waterproof
def __str__(self):
return f"{Shoe.__str__(self)}, openOrClosedToe: {self.openOrClosedToe}, waterproof: {self.waterproof}"
CODE SCREENSHOT (For indentation ref.)
Testing CODE:
cnv1 = Converse("red","low top","blue")
cnv2 = Converse("black","high top","teal")
print(cnv1)
print(cnv2)
cnv1 = CombatBoot("brown","Niki","marine","desert")
cnv2 = CombatBoot("black","Ranger","navy","jungle")
print(cnv1)
print(cnv2)
cnv1 = Sandal("yellow","Bata","Open top","yes")
cnv2 = Sandal("green","Niki","closed top","no")
print(cnv1)
print(cnv2)
TEST OUTPUT SCREENSHOT: