Question

In: Computer Science

Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose:...

Description: Create a class in Python 3 named Animal that has specified attributes and methods.

Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3.

Requirements:

Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py.

Attributes

__animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc.

__name is a hidden attribute used to indicate the animal’s name.

__mood is a hidden attribute used to indicate the animal’s mood. For example: happy, hungry, or sleepy.

Methods

__init__ is to define the three attributes above and assign their default values.

The value of __mood is to be set randomly. Generate a random number between 1 and 3. Then:

If the number is 1, the __mood attribute is to be set to a value of happy.
If the number is 2, the __mood attribute is to be set to a value of hungry.
If the number is 3, the __mood attribute is to be set to a value of sleepy.

get_animal_type should return the value of the __animal_type field.

get_name should return the value of the __name field.

check_mood should return the value of the __mood field.

Animal Generator Program

Once you have created the Animal class, create another Python file called animalGenerator.py. This program is to use Animal.py as a module.

In animalGenerator.py, prompt the user to enter the name and type of an animal. Create a new Animal object instance to store this data. Then, ask the user if they would like to repeat the process. They should be able to create as many Animal object instances as they would like.

After the user is done creating animals, the program is to use the object’s accessor methods (get_animal_type, get_name, and check_mood) to retrieve the name, type, and mood of each animal. This information is to be formatted and displayed as shown in the sample program output below.

Welcome to the animal generator!
This program creates Animal objects.

What type of animal would you like to create? Gecko
What is the animal’s name? Gordon

Would you like to add more animals (y/n)? y

What type of animal would you like to create? Walrus
What is the animal’s name? Wally

Would you like to add more animals (y/n)? y

What type of animal would you like to create? Tiger
What is the animal’s name? Truman

Would you like to add more animals (y/n)? n

Animal List:
Gordon the Gecko is hungry
Wally the Walrus is sleepy
Truman the Tiger is hungry

Testing

Run the program you write and verify that the information entered matches the information displayed and that the input prompts and output utilize the format specification provided.

PLEASE COPY DOWN CODE WITH INDENTATIONS :)

Solutions

Expert Solution

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================


import random


class Animal():
    def __init__(self, type, name):
        self.__animal_type = type
        self.__name = name
        self.__mood = random.choice(['happy', 'hungry', 'sleepy'])

    def get_animal_type(self):
        return self.__animal_type

    def get_name(self):
        return self.__name

    def check_mood(self):
        return self.__mood

========================================================================

from Animal import Animal


def main():

    animal_collection=[]
    print('Welcome to the animal generator!')
    print('This program creates Animal objects.\n')
    while True:
        type = input('What type of animal would you like to create? ')
        name=input('What is the animal\'s name? ')

        an_animal = Animal(type,name)
        animal_collection.append(an_animal)

        add_more=input('Would you like to add more animals (y/n)? ')
        if not add_more=='y':break


    print('Animal List:')
    for a in animal_collection:
        print('{} the  {} is {}'.format(a.get_name(),a.get_animal_type(),a.check_mood()))


main()

=======================================================================

`


Related Solutions

Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and...
Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and methods for holding the information for a document and write a program to test the class. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Document that has the following attributes and methods and is saved in the file Document.py. Attributes __title is a...
In java: -Create a class named Animal
In java: -Create a class named Animal
Here is the assignment description. * Create a class named 'Account' having the following private attributes...
Here is the assignment description. * Create a class named 'Account' having the following private attributes int accountNumber; double balance; * Write a constructor with parameters for each of the attributes. * Write another constructorwith one parameter for the accountNumber. * Write getter and setter methods for each of the private attributes. * Write a method void credit(double amount) which adds the given amount to the balance. * Write a method void debit(double amount) which subtracts the given amount from...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance of Dog and use its methods. Purpose: This application provides experience with creating classes and instances of objects in C#. Requirements: Project Name: Dog Target Platform: Console Programming Language: C# Documentation: Types and variables (Links to an external site.) (Microsoft) Classes and objects (Links to an external site.) (Microsoft) Enums (Links to an external site.) (Microsoft) Create a class called Dog. Dog is to...
In python- Create a class defined for Regression. Class attributes are data points for x, y,...
In python- Create a class defined for Regression. Class attributes are data points for x, y, the slope and the intercept for the regression line. Define an instance method to find the regression line parameters (slope and intercept). Plot all data points on the graph. Plot the regression line on the same plot.
Design and develop a class named Person in Python that contains two data attributes that stores...
Design and develop a class named Person in Python that contains two data attributes that stores the first name and last name of a person and appropriate accessor and mutator methods. Implement a method named __repr__ that outputs the details of a person. Then Design and develop a class named Student that is derived from Person, the __init__ for which should receive first name and last name from the class Person and also assigns values to student id, course, and...
Create a Python program that includes each feature specified below. Comments with a detailed description of...
Create a Python program that includes each feature specified below. Comments with a detailed description of what the program is designed to do in a comment at the beginning of your program. Comments to explain what is happening at each step as well as one in the beginning of your code that has your name and the date the code was created and/or last modified. The use of at least one compound data type (a list, a tuple, or a...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US...
Problem: Implement a class named StringParser, along with specified methods, that can read words from a...
Problem: Implement a class named StringParser, along with specified methods, that can read words from a text file, parse those words (such as finding palindromes), and write those words to a new file More specifically: 1. Write the StringParser class so that it has the following methods: a) public static void main(String[] args) -- The main driver of the program. Prompts the user for an input file, an output file, and a choice for what kinds of words to output....
Create a super class named Vehicle, which has the following attributes: VIN, engine size, Year, Speed....
Create a super class named Vehicle, which has the following attributes: VIN, engine size, Year, Speed. Check Add a subclass named Car, which has the following additional attributes: Wheel size, Model, Miles (OOD). Check Add another subclass to the vehicle superclass named Boat which has the following additional attributes: Hours, Gas type, Type (Fishing Boat, Deck boat, bowrider boat), and Check Write a method named DisplayInfo() in your main to display the information of the Vehicle. In this method print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT