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

In this programming assignment, you will create the following: • An Animal class

ID: 3776801 • Letter: I

Question

In this programming assignment, you will create the following:

• An Animal class that stores information about an animal.

• A PetStore class that stores and displays Animal objects.

• A petstoremanager program that uses the Animal and PetStore classes.

FOR ANIMAL CLASS: save 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.

__animal_available: a hidden attribute used to indicate if the animal is available for adoption.

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

get_available: this method should return the value of the __animal_available field.

FOR PetSotre Class: save as PetStore.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.

#THIS IS EXTRA CREDIT --> delete_animal: this method should ask the user for a name for a animal and then remove them from the 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.

PET STORE MANAGER PROGRAM: save as petstore,anager.py

In petstoremanager.py, create a PetStore object and print a menu with three options(four with extra credit): Add Animal, Delete 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 create an Animal object and use the Store object’s add_animal method to store the animal.

Delete Animal: choosing this option should trigger the PetStore object’s delete_animal method.

Show Animals: choosing this option should trigger the PetStore 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.

Program output User input is in orange Extra credit is in red If you don't de extra credit your menu should look like Pet Store Options 1. Add Animal 2. Show Animals 3. Exit Sample Program operation Pet Store Options 1. Add Animal 2. Delete Animal 3. Show Animals 4. Exit What would you like to do? 3 Animal List There are no animals in your Pet Store! Pet Store Options 1. Add Animal 2. Delete Animal 3. Show Animals 4. Exit What would you like to do? 1 What type of animal would you like to create? Platypus What is the animal's name? Penelope Is the animal available for adoption?(yn) y Pet Store Options 1. Add Animal

Explanation / Answer

Animal.py

import random

class Animal:

   def __init__(self,type, name, available):
       self.__animal_type = type
       self.__name = name
       self.__animal_available = "Yes" if(available=="y" or available=="Y") else "No"
       rand_mood = random.randrange(1,4); # generate a random number between[1,4)
       if(rand_mood==1):
           self.__mood = "happy"
       elif(rand_mood==2):
           self.__mood = "hungry"
       elif(rand_mood==3):
           self.__mood = "sleepy"

   def get_animal_type(self):
       return self.__animal_type

   def get_name(self):
       return self.__name

   def check_mood(self):
       return self.__mood

   def get_available(self):
       return self.__animal_available

   # return the details of a animal in string form
   def to_string(self):
       return "[ Name: "+self.__name+", Type: "+self.__animal_type+", Mood: "+self.__mood+", Available: "+self.__animal_available+" ]"

_______________________________________________________________________________________

PetStore.py

class PetStore:
   # __animals

   def __init__(self):
       self.__animals = []

   def add_animal(self,animal):
       self.__animals.append(animal)

   def delete_animal(self,animal_name):
       index = -1
       present = False    #flag to check if animal to be deleted is present in store
       for animal in self.__animals:
           index += 1
           if(animal.get_name()==animal_name):
               present = True
               break;
       if(not present):
           print animal_name +" is not available in the Pet Store!";
       else:
           del self.__animals[index];

   def show_animals(self):
       if(self.__animals==[]):
           print "There are no animals in the Pet Store!"
       else:
           index = 0;       # store the S.No. in list
           for animal in self.__animals:
               index+=1
               print `index`+". "+animal.to_string()

____________________________________________________________________________________________

petstoremanager.py

import Animal
import PetStore

petStore = PetStore.PetStore()

while(1):
   print " Pet Store Options"
   print "-----------------"
   print "1. Add Animal"
   print "2. Delete Animal"
   print "3. Show Animal"
   print "4. Exit "

   option = raw_input("What would you like to do? ")

   # manager wants to add an animal
   if(option=="1"):
       animal_type = raw_input("What type of animal whould you like to create? ")
       name = raw_input("What is the animal's name? ")
       available = raw_input("Is the animal available for adoption?(y/n) ")
       animal = Animal.Animal(animal_type,name,available)
       petStore.add_animal(animal)

   # manager wants to delete an animal
   elif(option=="2"):
       name = raw_input("What is the animal's name you would like to delete? ")
       petStore.delete_animal(name)

   # showing the list of animals present in store
   elif(option=="3"):
       print "Animal List"
       print "-----------"
       petStore.show_animals();

   # Exit the system
   else:
       break

____________________________________________________________________________________________

Output

Pet Store Options

-----------------

1. Add Animal

2. Delete Animal

3. Show Animal

4. Exit

What would you like to do? 1

What type of animal whould you like to create? XYZ

What is the animal's name? ABC

Is the animal available for adoption?(y/n) y

Pet Store Options

-----------------

1. Add Animal

2. Delete Animal

3. Show Animal

4. Exit

What would you like to do? 3

Animal List

-----------

1. [ Name: ABC, Type: XYZ, Mood: hungry, Available: Yes ]

Pet Store Options

-----------------

1. Add Animal

2. Delete Animal

3. Show Animal

4. Exit

What would you like to do? 2

What is the animal's name you would like to delete? ABC

Pet Store Options

-----------------

1. Add Animal

2. Delete Animal

3. Show Animal

4. Exit

What would you like to do? 3

Animal List

-----------

There are no animals in the Pet Store!

Pet Store Options

-----------------

1. Add Animal

2. Delete Animal

3. Show Animal

4. Exit

What would you like to do? 4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote