(Solved) : Write Class Named Neighborhoodpets Methods Adding Pet Deleting Pet Searching Owner Pet Sav Q43995445 . . .
Write a class named NeighborhoodPets that has methods for addinga pet, deleting a pet, searching for the owner of a pet, savingdata to a JSON file, loading data from a JSON file, and getting alist of all pet species. It will only be loading JSON files that ithas previously created, so the internal organization of the data isup to you.
***PYTHON 3 ONLY***
- The add_pet method takes as parameters the name of the pet, thespecies of the pet, and the name of the pet’s owner. If a pet hasthe same name as a pet that has already been added, then thefunction should just return without adding the new pet.
- The delete_pet method takes as a parameter the name of the petand deletes it.
- The get_owner method takes as a parameter the name of the petand returns the name of its owner.
- The save_as_json method takes as a parameter the name of thefile and saves it in json format with that name. You can assume theextension (if any) will be part of the provided name.
- The read_json method takes as a parameter the name of the fileto read and loads that file. This will replace the pets currentlyin memory.
- The get_all_species method takes no parameters and returns aset of the species of all pets.
For example, your class could be used like this:
np = NeighborhoodPets()np.add_pet(“Fluffy”, “gila monster”, “Oksana”)np.add_pet(“Tiny”, “stegasaurus”, “Rachel”)np.add_pet(“Spot”, “zebra”, “Farrokh”)np.save_as_json(“pets.json”)np.delete_pet(“Tiny”)spot_owner = np.get_owner(“Spot”)np.read_json(“other_pets.json”)species_set = np.get_all_species()
The file must be named: NeighborhoodPets.py
Expert Answer
Answer to Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet…
OR