Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

InfoTc 1040 Introduction to Problem Solving and Programming Zoo Class In this pr

ID: 3692789 • Letter: I

Question

InfoTc 1040 Introduction to Problem Solving and Programming Zoo Class In this programming assignment, you will create the following: • An Animal class that stores information about an animal. • A Zoo class that stores and displays Animal objects. • A zookeeper program that uses the Animal and Zoo classes. These elements are described below. Animal Class Write a class named Animal with the following attributes and methods. Save this class as Animal.py Attributes __animal_type: a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc. __name: a hidden attribute used to indicate the animal’s name. __mood: a hidden attribute used to indicate the animal’s mood. For example: happy, hungry, or sleepy. Methods __init__: this method should create the three attributes above and assign their default values. The value of __mood should be set randomly. Generate a random number between 1 and 3. Then: If the number is 1, the __mood field should be set to a value of “happy”. If the number is 2, the __mood field should be set to a value of “hungry”. If the number is 3, the __mood field should be set to a value of “sleepy”. get_animal_type: this method should return the value of the __animal_type field. get_name: this method should return the value of the __name field. check_mood: this method should return the value of the __mood field. Write a class named Zoo with the following attributes and methods. Save this class as Zoo.py Attributes __animals: a list used to store Animal objects. Methods __init__: use this method to create an empty list for __animals. add_animal: this method should receive an Animal object and append it to the __animals list. show_animals: this method will print information about each of the Animal objects within __animals. If no Animals have been added to the list, it should print out a message saying that there are no Animals.

Explanation / Answer

# This program defines the Animal class

import random

class Animal:

    # Define what happens when a new animal object is created

    def __init__(self, animal_type, animal_name):

        self.__animal_type = animal_type

        self.__name = animal_name

        self.__mood = "happy"

    # Return the animal's type

    def get_animal_type(self):

        return self.__animal_type

    # Return the animal's name

    def get_name(self):

        return self.__name

    # Determine and return the animal's mood

    def check_mood(self):

        # Pick a number between 1 and 3

        random_number = random.randint(1, 3)

        # Set the animal's mood based on the random number

        if random_number == 1:

            self.__mood = "happy"

        elif random_number == 2:

            self.__mood = "hungry"          

        elif random_number == 3:

            self.__mood = "sleepy"

        # Finally, return the mood

        return self.__mood

zoo.py:

import Animals

class Zoo:

    __animals = []

    # Use method to create an empty list for __animals

    def __init__(self):

        self.__animals = animal_list

    # Receive an Animal object and append it to the __animals list

    def add_animal(self, animal):

        self.__animals.append(animal)

    # Determine and return the animal's mood

    def show_animals(self):

        return animal_list