please answer part A-D. using OOP python. Thank you (1 mark) Submit only the getter and setter methods as answer. You do

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

please answer part A-D. using OOP python. Thank you (1 mark) Submit only the getter and setter methods as answer. You do

Post by answerhappygod »

please answer part A-D. using OOP python.
Thank you
(1 mark)
Submit only the
getter and setter methods as answer. You do not need to submit the
complete Pet class.
(4 marks)
(10 marks)
Menu
0. Exit
The choice is then
processed as shown in the sample run (input underlined). Your
application must handle the PetAgencyException as well as input
errors.
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 1
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 1 (468.79 KiB) Viewed 25 times
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 2
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 2 (518.28 KiB) Viewed 25 times
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 3
Please Answer Part A D Using Oop Python Thank You 1 Mark Submit Only The Getter And Setter Methods As Answer You Do 3 (86.56 KiB) Viewed 25 times
. Study the class diagram in Figure Q2. The PetOwner class, the Pet class, the Dog class, and the Cat class are described in Table Q2(a) to Table Q2(e) respectively. Assume the PetOwner class has been implemented. You will only implement the Pet and Dog classes. Demonstrate your understanding of how class hierarchy and association are used to organize information, and then construct the class hierarchy and association according to specification Pet (abstract) Pet Owner _name: str address str _init__(self, mame, address) nameser address addressset, newAddress) str_sestr Identification str namest date farth datetime owner: Pet Owner _init__(self, identification, name, dateOfBirth, owner) identification(selfst date of Birthself):datetime owner(self):PetOwner ownerself, newOwner) address(estr addressself newAddress) agein Human Yearsseifint (abstract) hd Friendlyself bool str_(selfstr Getter methods for identification, date of birth, owner and address. The getter for address should return the owner's address. A setter method for owner and address. The setter method for address should update the owner's address. An abstract method ageInHuman Years(self) which returns the age of the pet in human years. A method hdbFriendly(self) which returns False. str_(self) returns a string representation of a pet, including the age in human years and owner's detail if the pet has an owner, and the string None otherwise. Two example strings are shown here: Id: C031 HDB Friendly: False Name: Sparkle Date of Birth: 12 Jan 2018 Age in Human Year: 28 Owner Name: Peter Address: 12 Dunbar Road Cat Id: 0831 HDB Friendly: False Name: Sparkle Date of Birth: 12 Jan 2018 Age in Human Year: 28 Owner None Table Q2(b) ( The Cat class is a subclass of the Pet class. It has the same attributes as Pet. The Cat class has the following methods, in addition to the methods of the Pet class: ageInHuman Years(self) which returns the age of the cat in human years, computed according to these rules: - 0 to under first year since birth, 19 human years between first to under second year since birth, 24 human years add 4 human years for each subsequent year str_(self) returns a string representation of a cat. An example string is shown here: Cat Id: C831 HDB Friendly: False Name: Sparkle Date of Birth: 12 Jan 2018 Age in Human Year: 28 Owner Name: Peter Address: 12 Dunbar Road Table 02(c) Dog Cat agein Human fears(selfst str_(selfst habfriendly: bool _init__(self, identification, hdb Friendly, name, dateOfBirth, owner agein Human Year(sent hdbfriendly fool str_sestr Figure 02 The PetOwner class has the following attributes: name _address . The PetOwner class has the following methods: _init_(self, name, address) initialises a new pet owner with the parameters name and address. Getter methods for name and address. _str_(self) returns a string representation of a pet owner. An example string is shown here: Name: Peter Address: 12 Dunbar Road Table 02(a) a The Pet class is an abstract class. It has the following attributes: identification name dateOfBirth owner The Pet class has the following methods: _init__(self, identification, name, dateOfBirth, owner) initialises a new pet with the parameters identication, name, dateOfBirth and owner. The default value for the parameter owner is None. The Dog class is a subclass of the Pet class. It has the following attributes in addition to the attributes of the Pet class: hdbFriendly records whether a dog is allowed in a HDB unit under HDB regulations. The Dog class has the following methods, in addition to the methods of the Pet class: _init__(self, identification, hdbFriendly, name, dateOfBirth, owner) initialises a new pet with the parameters identification, hdbFriendly, name, dateOfBirth and owner. ageInHuman Years(self) which returns the age of the dog in human years, computed according to these rules: O to under first year since birth, 15 human years - between first to under second year since birth, add 9 human years add 5 human years for each subsequent year A method hdbFriendly(self) which returns whether a dog is hdbFriendly. _str_(self) returns a string representation of a dog. An example string is shown here: Dog Id: 0123 HDB Friendly: True Name: Jackie Date of Birth: 07 Dec 2019 Age in Human Year: 15 Owner Name: Peter Address: 12 Dunbar Road Table 02(d) .
The Pet Adoption Agency class has the following attributes: pets is a list of pets managed by the pet adoption agency. Apply the principles of object-oriented programming and develop an application where pets in a pet adoption agency are managed. Study the class diagram in Figure Q3 which is an extension of Figure Q2. The PetAgencyException class and the PetAdoption Agency are described in Table Q3(a) and Table Q3(b) respectively. Refer to Table Q2(a) to Table Q2(d) for the description of the other classes. You will implement the PetAgencyException and PetAdoptionAgency classes, and make modification to the getter and setter method for address in the Pet class. Pet (abstract) ) The PetAdoption Agency class has the following methods: _init__(self) initialises a new pet adoption agency with an empty list of pets. searchPet(self, identification):Pet returns a pet with the parameter identification if _pets contain a pet with the parameter identification. Otherwise, it returns None. addPet(self, pet):bool adds the parameter pet to _pets, if_pets does not contain the pet already. If the add is successful, the method returns True. Otherwise, raises a PetAgency Exception exception with the message Duplicate pet identification. Cannot add. • adopt(self, owner, identification):bool assigns the parameter owner as owner of the pet with the parameter identification and returns True. However, - if a pet cannot be located with the parameter identification, the method raises PetAgencyException exception with the message Incorrect pet identification. Cannot adopt. if a pet already has an owner, the method raises PetAgencyException exception with the message Pet already has an owner. Cannot be adopted. If the owner has already adopted 2 pets from the agency, disallow the adoption. The method raises PetAgencyException exception with the message Owner has adopted two pets already. Adoption quota reached. Note that owners are determined by their names and addresses. updateAddress(self, identification, address): bool locates the pet with the parameter identification and updates its address with the parameter address. If a pet cannot be located with the parameter identification, the method raises PetAgencyException exception with the message Incorrect pet identification. Cannot update address. Table 03(b) b PetOwner Pet Adoption Agency name: address str initself, name, address) namestr address self str addresse,Address identification str namesto dateOfBirth: datetime Owner Pet Owner _init__(self, identification, name, dateOrBirthowner) identificationsstr dateOfBirth datetime Owner:Pet Owner Owners, newOwner addresses address, new Address) opelnuman Yearsal fine abstract) hd Friendlysbool _str_sestr pets init sel searchPets, identification: Pet addetiselt petool adoptPetselt, owner, identification tool , strselfjestr PetAgency Exception (a) Define the exception class PetAgencyException. Dog Cat (1 mark) (b) db Friendly:bool init_self, identification, hd friendly, name, dateOrBirth, Owner) again Human Years(self)ant agen Human years sont str_selfstr hd Friendly self bod str selfs Figure 03 A pet may not have an owner. Modify getter and setter methods for address in the Pet class according to the description: Getter method: The method returns the owner address if the pet has an owner. Otherwise, the method raises a PetAgencyException exception with the message Pet has no owner. No owner address to retrieve. Setter method: The method updates the owner's address if the pet has an owner. Otherwise, the method raises a PetAgencyException exception with the message Pet has no owner. No owner address to update. The PetAgencyException class is a subclass of Exception. It has no additional attribute. A PetAgencyException object is raised when there is a business rule violation. The PetAgencyException class has no additional method. Table 03a) Submit only the getter and setter methods as answer. You do not need to submit the complete Pet class. (4 marks) (c) Implement the PetAdoptionAgency class. (10 marks)
(d) Implement an application that starts by creating a PetAdoption Agency with pets as shown in Table Q3(C), and then repeatedly allows the user to select one of the choices in the menu: Menu 1. Update pet address 2. Adopt a pet @. Exit The choice is then processed as shown in the sample run (input underlined). Your application must handle the PetAgencyException as well as input errors. Pet Identification HDB Name Date of Birth Owner Friendly Dog D123 Yes Jackie 7 Dec 2019 C031 Sparkle 12 Jan 2018 C017 Ginger 12 Jan 2018 Address: 12 Dunbar Road Table 03(c) Cat Cat Name: Peter Sample run: Menu 1. Update pet address 2. Adopt a pet e. Exit Enter a choice: a Please enter a number for menu choice. Menu 1. Update pet address 2. Adopt a pet e. Exit Enter a choice: Please enter a number for menu choice. Menu 1. Update pet address 2. Adopt a pet e. Exit Enter a choice: 1 Enter pet identification: 0123 Enter new address: 2 Dunbar Road Pet has no owner. No owner address to update Menu 1. Update pet address 2. Adopt a pet e. Exit Enter a choice: 1 Enter pet identification: D12 Enter new address: 2 Dunbar Road Incorrect pet identification. Cannot update address Menu 1. Update pet address 2. Adopt a pet e. Exit Enter a choice: 1 Enter pet identification: 2017 Enter new address: 2 Dunbar Road Update address: True Menu 1. Update pet address 2. Adopt a pet 8. Exit Enter a choice: 2 Enter Owner name: Tom Enter address: 34 Grey Lane Enter pet identification: 2017 Pet already has an owner. Cannot be adopted Menu 1. Update pet address 2. Adopt a pet . Exit Enter a choice: 2 Enter owner name: Tom Enter address: 34 Grey Lane Enter pet identification: 012 Incorrect pet identification. Cannot adopt Menu 1. Update pet address 2. Adopt a pet 8. Exit Enter a choice: 2 Enter owner name: Peter Enter address: 2 Dunbar Road Enter pet identification: Ce31 Adoption: True Menu 1. Update pet address 2. Adopt a pet 8. Exit Enter a choice: 2 Enter owner name: Peter Enter address: 12 Dunbar Road Enter pet identification: 0123 Owner has adopted two pets already. Adoption quota reached Menu 1. Update pet address 2. Adopt a pet . Exit Enter a choice: @ Application ends (13 marks)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply