FOR PYTHON 1) Create a Shoe superclass with two subclasses based on the pseudo c
ID: 3833645 • Letter: F
Question
FOR PYTHON
1) Create a Shoe superclass
with two subclasses based on the pseudo code.
2) Implement given attributes and methods getType(), describe() for subclasses.
Class Shoe
Attributes: Color, size
Methods:
getType() -return "shoe“
describe() -return a string describing the shoe with its attributes
i.e.) Yellow shoe size 7.
Class Boot inherits from Shoe
Attributes: height
Methods:
getType() -return "boot"
describe () -return a string describing the boot with its attributes
Class Sneaker inherits from Boot
Attributes: lace_color
Methods:
getType() -return “sneaker"
describe() -return a string describing the boot with its attribute
Explanation / Answer
class Shoe(object):
def __init__(self, color, size):
self.color = color
self.size = size
def getType(self):
return "shoe"
def describe(self):
return str(self.color) + " " + self.getType() + " size " + str(self.size)
class Boot(Shoe):
def __init__(self, color, size, height):
super(Boot, self).__init__(color, size)
self.height = height
def getType(self):
return "boot"
def describe(self):
return super(Boot, self).describe() + " height " +str(self.height)
class Sneaker(Boot):
def __init__(self, color, size, height, lace_color):
super(Sneaker, self).__init__(color, size, height)
self.lace_color = lace_color
def getType(self):
return "sneaker"
def describe(self):
return super(Sneaker, self).describe() + " lace color " + str(self.lace_color)
shoe = Shoe("Blue", 7)
print(shoe.describe())
boot = Boot("Brown", 9, 3)
print(boot.describe())
sneaker = Sneaker("Black", 8, 2, "brown")
print(sneaker.describe())
# code link https://paste.ee/p/vkwRW
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.