Пример #1
0
def defaultShelter(shelter):
    """This is a default Shelter for the purposes of a demo
    """

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Dog('German Shepard', 'Fido', 'M', 5, 40, shelter.get_ID(),
                    True), shelter.pet_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Dog('Golden Retriever', 'Goldy', 'F', 6, 53, shelter.get_ID(),
                    True), shelter.pet_directory)
    shelter.update_Pet_Status(2, 'Adopted')

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Cat('Mixed', 'Fluffy', 'F', 8, 5, shelter.get_ID(), 'Indoors'),
        shelter.pet_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Bird('Parrot', 'Chirps', 'M', 3, 1.3, shelter.get_ID(),
                     'Both'), shelter.pet_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Cat('Spinx', 'Mushu', 'F', 2, 6, shelter.get_ID(), 'Indoors'),
        shelter.pet_directory)
    shelter.update_Pet_Status(5, 'On-Hold')

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Reptile('Bearded Dragon', 'Toasty', 'Unknown', 4, 2.6,
                        shelter.get_ID(), 92), shelter.pet_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Rabbit('Unknown', 'Hops', 'F', 1, 3, shelter.get_ID()),
        shelter.pet_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Dog('Unknown', 'Ruff', 'M', 3, 30, shelter.get_ID(), False),
        shelter.pet_drop_directory)

    shelter.increment_ID()
    shelter.add_Pet(
        animals.Bird('Parrot', 'Squeks', 'F', 2, 2, shelter.get_ID(), 'Caged'),
        shelter.pet_directory)
    shelter.update_Pet_Status(9, 'On-Hold')

    shelter.admin_directory.append(Admin('Jacob', 1))
def main():
    # This is wrong, since animal is abstract.
    # However, Python does not prevent you from doing it.
    animal = animals.Animal('Harry', 65)
    # The below will throw an error, since eat() relies on primaryFood(),
    # which is not implemented in the base class.
    # animal.eat()

    # Should never do this.
    # tailedAnimal = animals.TailedAnimalMixin('Rex', tailLength=6.5)

    dog = animals.Dog('Rex', 65, tailLength=6.5, breed='Dalmatian')
    dog.bark()
    dog.eat()
    dog.sleep()
    dog.wagTail()
    print dog.weight()
    dog.takeToVet()

    # Bat itself does not have an __init__, but its first base class (WingedAnimalMixin) does.
    # Hence, we pass in three parameters, to match the signature of WingedAnimalMixin's __init__.
    bat = animals.Bat('Ted', 0.5, wingSpan=1.2)
    bat.fly()
    print bat.weight()
    bat.land()
    print bat.weight()
    bat.eat()
    bat.sleep()
    bat.hangUpsideDown()
Пример #3
0
    def createPet(self, shelter):

        #Gets all required info from user
        pet_info = helper.get_input_pet(shelter.animal_types)

        #Create appropriate Pet class, increment ID before creating pet to get a unique ID
        if pet_info[0].lower() == 'dog':
            shelter.increment_ID()
            return (animals.Dog(pet_info[1], pet_info[2],
                                pet_info[3], pet_info[4], pet_info[5],
                                shelter.get_ID(), pet_info[6]))

        elif pet_info[0].lower() == 'cat':
            shelter.increment_ID()
            return (animals.Cat(pet_info[1], pet_info[2],
                                pet_info[3], pet_info[4], pet_info[5],
                                shelter.get_ID(), pet_info[6]))

        elif pet_info[0].lower() == 'bird':
            shelter.increment_ID()
            return (animals.Bird(pet_info[1], pet_info[2],
                                 pet_info[3], pet_info[4], pet_info[5],
                                 shelter.get_ID(), pet_info[6]))

        elif pet_info[0].lower() == 'reptile':
            shelter.increment_ID()
            return (animals.Reptile(pet_info[1], pet_info[2],
                                    pet_info[3], pet_info[4], pet_info[5],
                                    shelter.get_ID(), pet_info[6]))

        elif pet_info[0].lower() == 'rabbit':
            shelter.increment_ID()
            return (animals.Rabbit(pet_info[1], pet_info[2], pet_info[3],
                                   pet_info[4], pet_info[5], shelter.get_ID()))
Пример #4
0
def main():
    # Create a Mammal object, a Dog object, and a Cat object.
    mammal = animals.Mammal('regular animal')
    dog = animals.Dog()
    cat = animals.Cat()
    # display information about each one.
    print('Here are some animals and')
    print('the sounds they make.')
    print('--------------------------')
    show_mammal_info(mammal)
    print()
    show_mammal_info(dog)
    print()
    show_mammal_info(cat)
Пример #5
0
def main():
    mammal = animals.Mammal('Regular Animal')
    dog = animals.Dog()
    cat = animals.Cat()

    print('Animals and the sound they make')
    print('-----------------------------')
    show_mammal_info(mammal)
    print()
    show_mammal_info(dog)
    print()
    show_mammal_info(cat)
    print()
    show_mammal_info('I am a string')
Пример #6
0
def main():
# Create a Mammal object, a Dog object, and
# a Cat object.
    mammals = list()
    mammals.append(animals.Mammal('regular animal'))
    mammals.append(animals.Dog())
    mammals.append(animals.Cat())
    mammals.append(animals.Siberian_Husky())
# Display information about each one.
    print('Here are some animals and')
    print('the sounds they make.')
    print('--------------------------')
    for mammal in mammals:
        show_mammal_info(mammal)
            print()
Пример #7
0
def main():

	mammal = animals.Mammal('regular animal')
	dog = animals.Dog()
	cat = animals.Cat()

	# Display information about each one.
	print('Here are some animals and' 
		+ 'the sounds they make.')
	print('--------------------------------')
	show_mammal_info(mammal)
	print()
	show_mammal_info(dog)
	print()
	show_mammal_info(cat)
Пример #8
0
def main():
    mammal = animals.Mammal('regular animal')
    dog = animals.Dog()
    cat = animals.Cat()

    print('Here are some animals and\nthe sound they make:')
    print('-------------------------')

    show_mammal_info(mammal)
    print()

    show_mammal_info(dog)
    print()

    show_mammal_info(cat)
Пример #9
0
    def test_check_age(self):
        animal = 'dog'
        name = 'Lola'
        n_legs = 4
        gender = 'F'
        speech_type = 'bau'
        breed = 'Chihuahua'
        age = 1

        test_animals = animals.Dog(animal, name, n_legs, gender, speech_type,
                                   breed, age)

        test_animals.age = age
        # self.assertIsInstance(age, float), 'Number must be a integer!'
        self.assertIsInstance(age, int)
Пример #10
0
def main():
    # Utworzenie obiektów klas
    # Mammal, Dog i Cat.
    mammal = animals.Mammal('zwierzę')
    dog = animals.Dog()
    cat = animals.Cat()

    # Wyświetlenie informacji o każdym zwierzęciu.
    print('Oto kilka przykładów zwierząt')
    print('i wydawanych przez nie dźwięków.')
    print('--------------------------')
    show_mammal_info(mammal)
    print()
    show_mammal_info(dog)
    print()
    show_mammal_info(cat)
Пример #11
0
    def test_is_rescue_dog(self):
        animal = 'dog'
        name = 'Lola'
        n_legs = 4
        gender = 'F'
        speech_type = 'bau'
        breed = 'Chihuahua'
        age = 1

        test_animals = animals.Dog(animal, name, n_legs, gender, speech_type,
                                   breed, age)

        result = test_animals.is_rescue_dog()

        self.assertTrue(result,
                        f'{name} is a {breed} hence it is not a rescue dog')
Пример #12
0
def main():
    # Создать объект Mammal, объект Dog
    # и объект Cat.

    mammal = animals.Mammal('Обычное животное')
    dog = animals.Dog()
    cat = animals.Cat()

    # Показать информацию о каждом животном.
    print('Вот несколько животных и')
    print('звуки, которые они издают.')
    print('--------------------------')
    show_mammal_info(mammal)
    print()
    show_mammal_info(dog)
    print()
    show_mammal_info(cat)
Пример #13
0
import animals 
import shapes

#Implementation of classes for various animals and shapes (10 classes each) to learn abstraction and encapsulation, public and private access specifiers in Python
print("Details of animals.....\n")
a1 = animals.Animal()
a1.set_kingdom("Mammal")
a1.set_lifespan("20")
a1.displaydetails()
print("\n")

d1 = animals.Dog()
d1.set_name()
d1.set_lifespan("20")
d1.displaydetails()
d1.animalProperty()
print("\n")

liz1 = animals.Lizard()
liz1.set_name()
liz1.set_lifespan("10")
liz1.displaydetails()
liz1.animalProperty()
print("\n")

b1 = animals.Butterfly()
b1.set_name()
b1.set_lifespan("2")
b1.displaydetails()
b1.animalProperty()
print("\n")
Пример #14
0
            self.__species = species
        def show_species(self):
            print('I am a', self.__species)
        def make_sound(self):
            print('Grrrrr')
    # dog class inherits species, show_species and make_sound
    class Dog(Mammal): 
        def __init__(self):
            Mammal.__init__(self, 'Dog') # overrides species with "Dog"
        def make_sound(self): # overrides make_sound
            print('Woof! Woof!')

# from program file polymorphism_demo.py
    import animals
    mammal = animals.Mammal('regular animal') # create mammal object
    dog = animals.Dog() # create dog object

    # call show_species and make_sound methods from superclass
    mammal.show_species() 
    mammal.make_sound()

    # call show_species and make_sound methods from subclass
    dog.show_species()
    dog.make_sound()
    ### OUTPUT ###
        # I am a regular animal
        # Grrrrr
        # I am a Dog
        # Woof! Woof!

###### isinstance and issubclass functions ######
        print('Le ', end='')
        self._target.say_hi()


class Canadian:
    def __init__(self, target):
        self._target = target

    def say_hi(self):
        self._target.say_hi()
        print('Eh?')


# Use inheritance sparingly. Instead of making FrenchDog and FrenchHuman
# and CanadianDog and FrenchCanadianDog ... just one decorator to apply
# to any animal.

import animals

# This is the DECORATOR design pattern. Decorating an object with another.
# Pass the "target" into the constructor. The book talks about this
# pattern and the terminology. Makes it easier for you to discuss as a
# team ... "we'll use the decorator pattern here and blah blah blah"

dog = French(animals.Dog())
human = French(Canadian(animals.Human()))

print('---')

dog.say_hi()
human.say_hi()
Пример #16
0
import animals

mammal = animals.Mammal('Regular mammal')
mammal.show_species()
mammal.make_sound()

cat = animals.Cat()
cat.show_species()
cat.make_sound()

dog = animals.Dog()
dog.show_species()
dog.make_sound()
Пример #17
0
import animals


def testDuck(duck):
    duck.quark()


duck = animals.Duck('Tommy')
testDuck(duck)
dog = animals.Dog('Fox')
testDuck(dog)
Пример #18
0
import animals
fido = animals.Dog()
fido.learn_name("Fido")
fido.hear("hey, fido, hear me?!")
Пример #19
0
import animals

animal = animals.Animal("fred")
animal.walk().walk().walk().run().run().displayHealth()
dog = animals.Dog("Bob")
dog.walk().walk().walk().run().run().pet().displayHealth()
dragon = animals.Dragon("frank")
dragon.walk().walk().walk().run().run().fly().fly().displayHealth()
Пример #20
0
import animals as a
""" Animals has a super class of animal along with several subclasses """

x = a.Dog('Fido')
hearMe = x.speak("Woof, woof")

print(hearMe)

Пример #21
0
import animals
import dog_park

# Initialize / create names for variables that will use animals' methods
#required with dunder init in animals file

burt = animals.Dog("Burt")
ann = animals.Husky("Ann")
chippy = animals.Chihuahua("Chippy")
zorro = animals.Labrador("Zorro")
jake = animals.Cat()

dogs = [
    animals.Husky("Ann"),
    animals.Chihuahua("Chippy"),
    animals.Labrador("Zorro")
]
park = dog_park.DogPark(dogs)

park.converse()

# burt.speak()
# burt.eat()
# burt.learn_name("Burt")
# print (burt.name)
burt.call_dog("Come here Burt")
burt.call_dog("Burt, do you want to play")
burt.call_dog("Come here dumb dog")
burt.call_dog("Burt, I have a snack")

# jake.eat()
Пример #22
0
import animals
import dogpark

rue = animals.lab("Rue")

#rue.speak()
rue.food('treat')
rue.food('spinach')
#rue.knows_name("Does Rue know her name now?")
print(rue.name)
rue.count_barks()
vegas = animals.Dog("Vegas")
print(vegas.name)
vegas.count_barks()
rue.count_barks()
eastside = dogpark.DogPark([rue, vegas])
eastside.rollcall()
eastside.converse()
#whisk = animals.Cat("whiskers")
#print(whisk.mood, whisk.name)
#whisk.speak()
#whisk.mood = "happy"
#whisk.speak()