Question: Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to

 Write a class named NeighborhoodPets that has methods for adding a

Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. - The init method takes no parameters and initializes any data members, which must all be private. - The add_pet method takes as parameters the name of the pet, the species of the pet, and the name of the pet's owner. If a pet has the same name as a pet that has already been added, then the function should raise a DuplicateNameError and not add the pet (you'll need to define this exception class). - The delete_pet method takes as a parameter the name of the pet and deletes that pet. - The get_owner method takes as a parameter the name of the pet and returns the name of its owner. - The save_as_json method takes as a parameter the name of a file and saves it in JSON format with that name. You can assume the file extension (if any) will be part of the name that is passed in. You can organize your JSON file however you want. - The read_json method takes as a parameter the name of a file to read and loads that file. This will replace all of the pets currently in memory. - The get_all_species method takes no parameters and returns a Python set of the species of all pets. For example, your class could be used like this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!