Question

Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...

Assignment Statement

Use the skeleton file starter code (below) to create the following classes using inheritance:
⦁   A base class called Pet
⦁   A mix-in class called Jumper
⦁   A Dog class and a Cat class that each inherit from Pet and jumper
⦁   Two classes that inherit from Dog: BigDog and SmallDog
⦁   One classes that inherit from Cat: HouseCat

The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but you will have to identify the required inheritance for a class. You will be responsible for writing the functionality of those classes.

A description of each class’s functionality, as well as the data to use, is in the requirements below.

You will be required to write the code to exercise your classes per the requirements.

Requirements:
Use the provided template to complete the following. The details are in the skeleton file (see below).

1. The Pet class:
a. Assign values to two variables: kind and color
b.   Implement the constructor to initialize the pet’s name
c.   Implement do_tricks method per skeleton (see Skeleton file below)
2. The Jumper class
a.   Implement the jump method per the skeleton (see Skeleton file below)
3. The Dog class
a.   Decide which classes to inherit from and implement inheritance
b.   Change the kind to canine
c.   Implement __str__ per skeleton (see Skeleton file below)
d.   Implement __call__ per skeleton (see Skeleton file below)
4. The BigDog class
a.   Change the color to tan
b.   Implement __str__ per skeleton (see Skeleton file below)
c.   Implement speak per skeleton (see Skeleton file below)
5. The SmallDog class
a.   Change the color to brindle
b.   Implement __str__ per skeleton (see Skeleton file below)
c.   Implement speak per skeleton (see Skeleton file below)
6. The Cat class
a.   Change the kind to feline
b.   Implement __str__ per skeleton (see Skeleton file below)
c.   Implement speak per skeleton (see Skeleton file below)
d.   Implement climb per skeleton (see Skeleton file below)

7. The HouseCat class
a.   Change the color to white
b.   Implement __str__ per skeleton (see Skeleton file below)
c.   Implement speak per skeleton (see Skeleton file below)
8. Run the code according to the following:
a.   Instantiate each class(except jumper)
b.   Create a list of the instantiated objects
c.   Loop through the objects
d.   For each object:
   i.   Print __str__
ii.   print the kind of pet

iii.   Print the Color of the pet

   iv.   Have the pet do tricks
   v.   if applicable, print rollover action and the owners name
   vi.   If applicable, have the pet climb
   vii.   To separate each pet print underscores

Sample Output
Your output should look something like this

<__main__.Pet object at 0x101eaa898>
animal
brown
Taz is doing tricks
----------------------------------------
I am a cat named Lion
feline
brown
Lion is doing tricks
Lion says Meow!!!
Lion is jumping
Lion is climbing the curtains again
----------------------------------------
I am a dog named Roo
canine
brown
Roo is doing tricks
Roo is jumping
Roo is rolling over
My owner is George
----------------------------------------
Noah is a large, muscular dog
canine
tan
Noah is doing tricks
Noah says Woof!!!
Noah is jumping
Noah is rolling over
My owner is George
----------------------------------------
Lucky is a tiny, cute dog
canine
brindle
Lucky is doing tricks
Lucky says Yip!
Lucky is jumping
Lucky is rolling over
My owner is George
----------------------------------------
Zebra is a cat with fluffy, white fur
feline
white
Zebra is doing tricks
Zebra says Purr
Zebra is jumping
Zebra is climbing the curtains again
----------------------------------------

Process finished with exit code 0

Hints (what to do in each class)

Pet class:

1.   Variable assignment
2.   Implement constructor
3.   Implement do_tricks
a.   Print statement
b.   Call speak method
c.   Call jump method

Jumper Class:
4.   Implement jump

Dog Class
5.   Add inheritance
6.   Change kind variable
7.   Implement __str__
8.   Implement __call__

BigDog Class
9.   Add inheritance
10.   Change color to tan
11.   Implement __str__
12.   Implement speak

SmallDog class
13.   Add inheritance
14.   Change color to brindle
15.   Implement __str__
16.   Implement speak

Cat class
17.   Add inheritance
18.   Change kind to feline
19.   Implement __str__
20.   Implement speak
21.   Implement climb

HouseCat class
22.   Add inheritance
23.   Change color to white
24.   Implement __str__
25.   Implement speak

How Use your code
26.   Instantiate each class(except jumper)
27.   Create a list of the instantiated objects
28.   Loop through the objects
29.   Print __str__
30.   print the kind of pet
31.   Print the Color of the pet
32.   Have the pet do tricks
33.   if applicable, print rollover action and the owners name
34.   If applicable, have the pet climb
35.   To separate each pet print underscores

Skeleton File (to start with)

class Pet:
    #Create two variables kind and color; assign values

    def __init__(self, name):
        #In the constructor, initialize the pets name

    def do_tricks(self):  
        #Print the name of the pet and that it is doing tricks
        #Call the speak method
        #Call the jump method

    def speak(self):
        pass

    def jump(self):
        pass

class Jumper:
    'This is a mixin class for jump'

    def jump(self):
        #Create jump method that prints that a Pet is jumping and the pets name

class Dog:  #You will need to inherit for this to work
    #Change kind to canine

    def __str__(self):
        #Print the name and description of dog

    def __call__(self, action):
        #Rollover action prints the name of the dog and that it is rolling over
        #Owner action returns the name of the owner

class BigDog:  #You will need to inherit for this to work
    # Change the color to tan

    def __str__(self):
        #Print the name and description of BigDog

    def speak(self):       
        # Print dogs name and what it says

class SmallDog:  #You will need to inherit for this to work
    # Change the color to brindle

    def __str__(self):
        #Print the name and description of SmallDog

    def speak(self):       
        # Print dogs name and what it says

class Cat:  #You will need to inherit for this to work
    #Change the kind to feline

    def __str__(self):
        #Print the name and description of cat

    def speak(self):
        # Print cats name and what it says

    def climb(self):
        #Prints the name of the cat and that it is climbing

class HouseCat:  #You will need to inherit for this to work
    #Change the color to white

    def __str__(self):
        #Print the name and description of cat

    def speak(self):
        # Print cats name and what it says

###########################################
#EXERCISE YOUR CODE
#    1. Instantiate each class(except jumper)
#    2. Create a list of the instantiated objects
#    3. Loop through the objects
#    4. Print __str__
#    5. print the kind of pet
#    6. Print the Color of the pet
#    7. Have the pet do tricks
#    8. if applicable, print rollover action and the owners name
#    9. If applicable, have the pet climb
#   10. To separate each pet print underscore

Homework Answers

Answer #1
class Pet:
    # Create two variables kind and color; assign values
    kind = "animal"
    color = "black"

    speak_script = "{name} says {sound}"
    str_script = "I am a {kind} named {name}"

    def __init__(self, name):
        # In the constructor, initialize the pets name
        self.name = name

    def do_tricks(self):
        # Print the name of the pet and that it is doing tricks
        print("{name} is doing tricks".format(name=self.name))

        # Call the speak method
        self.speak()

        # Call the jump method
        self.jump()

    def speak(self):
        pass

    def jump(self):
        pass


class Jumper:
    'This is a mixin class for jump'

    def jump(self):
        # Create jump method that prints that a Pet is jumping and the pets name
        print("{name} is jumping".format(name=self.name))


class Dog(Jumper, Pet):  # You will need to inherit for this to work

    # Change kind to canine
    kind = "canine"
    owner = "Jenny"

    def __str__(self):
        # Print the name and description of dog
        return ("I am a {kind} named {name}".format(name=self.name, kind=self.kind))

    def __call__(self, action):
        if action == "rollover":
            # Rollover action prints the name of the dog and that it is rolling over
            print("{name} is rolling over".format(name=self.name))
        elif action == "owner":
            # Owner action returns the name of the owner
            print("The owner is: " + self.owner)


class BigDog(Dog):  # You will need to inherit for this to work

    # Change the color to tan
    color = "tan"

    owner = "Rachel"

    spoken_sound = "WOOF!"

    def __str__(self):
        # Print the name and description of BigDog
        return ("I am a {kind} named {name}".format(name=self.name, kind=self.kind))

    def speak(self):
        # Print dogs name and what it says
        print(self.speak_script.format(name=self.name, sound=self.spoken_sound))


class SmallDog(Dog):  # You will need to inherit for this to work
    spoken_sound = "woof"

    owner = "Alexander"

    # Change the color to brindle
    color = "brindle"

    def __str__(self):
        # Print the name and description of SmallDog
        return ("I am a {kind} named {name}".format(name=self.name, kind=self.kind))

    def speak(self):
        # Print dogs name and what it says
        print(self.speak_script.format(name=self.name, sound=self.spoken_sound))


class Cat(Jumper,Pet):  # You will need to inherit for this to work

    spoken_sound = "Meow"

    # Change the kind to feline
    kind = "feline"

    def __str__(self):
        # Print the name and description of cat
        return ("I am a {kind} named {name}".format(name=self.name, kind=self.kind))

    def speak(self):
        # Print cats name and what it says
        print(self.speak_script.format(name=self.name, sound=self.spoken_sound))

    def climb(self):
        # Prints the name of the cat and that it is climbing
        print("{name} is climbing".format(name=self.name))


class HouseCat(Cat):  # You will need to inherit for this to work
    spoken_sound = "meyow"

    # Change the color to white
    color = "white"

    def __str__(self):
        # Print the name and description of cat
        return ("I am a {kind} named {name}".format(name=self.name, kind=self.kind))

    def speak(self):
        # Print cats name and what it says
        print(self.speak_script.format(name=self.name, sound=self.spoken_sound))


###########################################

# EXERCISE YOUR CODE

# #   1. Instantiate each class(except jumper)
# #   2. Create a list of the instantiated objects
# #   3. Loop through the objects
# #   4. Print __str__
# #   5. print the kind of pet
# #   6. Print the Color of the pet
# #   7. Have the pet do tricks
# #   8. if applicable, print rollover action and the owners name
# #   9. If applicable, have the pet climb
# #  10. To separate each pet print underscores

def main():
    pet = Pet("Animal")
    dog = Dog("Rocky")
    big_dog = BigDog("Clifford")
    small_dog = SmallDog("Spuds")
    cat = Cat("Heathcliff")
    house_cat = HouseCat("Garfield")

    pets = [pet, dog, big_dog, small_dog, cat, house_cat]

    for pet in pets:
        print(pet.__str__())
        print(pet.kind)
        print(pet.color)
        pet.do_tricks()
        if callable(pet):  # more loosely coupled than if "__call__()" in dir(pet) or if pet.kind == "canine":
            pet("rollover")
            pet("owner")
        if "climb()" in dir(pet):  # more loosely coupled than if pet.kind == "feline":
            pet.climb()
        print("________________________")


main()
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT