Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started