Zoo Class
(Not rated)
(Not rated)
[removed]
InfoTc 1040 Introduction to Problem Solving and Programming
Zoo Class
In this programming assignment, you will create the following:
•
An Animal class
that
store
s
information about an animal.
•
A Zoo class
that
store
s
and display
s
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
r
eturn the value of the
__mood
field.
InfoTc 1040 Introduction to Problem Solving and Programming
Zoo Class
Zoo Class
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.
Zookeeper
Program
Once you have wri
tten the Animal and Zoo classes, create another program called
zookeeper.py
. This program will use
Animal.py
and
Zoo.py
as modules.
In zookeeper.py, create a Zoo object and print a menu with three options: Add
Animal, Show Animals, and Exit.
Add Animal:
choosing this option should prompt the user to enter the type
and name of an Animal. Use that input to creat
e an Animal object and use the
Zoo object’s
add_animal
method to store the animal.
Show Animals:
choosing this option should trigger the Zoo object’s
show_animals
method.
Exit:
this should exit the program.
If exit is not selected, the program should
loop and display the options again.
InfoTc 1040 Introduction to Problem Solving and Programming
Zoo Class
Sample Program Operation
User input is highlighted in
orange
.
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
2
Animal List
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
There are no animals in your zoo!
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
1
What type of animal would you like to create?
P
latypus
What is the animal's name?
Penelope
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
1
What type of animal would you like to create?
F
ox
What is the animal's name?
Frank
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
InfoTc 1040 Introduction to Problem Solving and Programming
Zoo Class
What would you like to do?
1
What type of animal would you like to create?
S
hark
What is the animal's name?
Sally
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
2
Animal List
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
Penelope the P
latypus is sleepy
Frank the
F
ox is hungry
Sally the S
hark is hungry
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
3
Thank you for visiting the zoo!
Error Checking
Invalid input should not cause the program to crash. Make sure to handle errors
properly. For example:
Zoo Options
-‐-‐-‐-‐-‐-‐-‐-‐-‐
-‐-‐
1. Add Animal
2. Show Animals
3. Exit
What would you like to do?
-‐
1
Please select a valid option.
InfoTc 1040 Introduction to Problem Solving and Programming
Zoo Class
What would you like to do?
one
Please enter a numeric value.
What would you like to do?
4
Please select a valid option.
What would you like to do?
3
Thank you for visiting the zoo!
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.
Submission
Put your
Animal
.py
,
Zoo
.py
,
and
zookeeper.py
file
s
in a folder named
<lastname><firstname>Zoo
and zip the folder. Do not include characters other
than a
-‐‑
z and A
-‐‑
Z in the folder name. The zip file is to be submitted for this
assignment.
If you need additional help,
post your questions on the class Help discussion
board or contact an eLearning mentor.
11 years ago
the answer 100 % correct answer. in python 3.4
NOT RATED
Purchase the answer to view it

- the-code.zip