Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 1523 Program 4 Write a program that creates three pet objects, adds them to a list, and then prints all the objects by iterating

CSCI 1523 Program 4

Write a program that creates three pet objects, adds them to a list, and then prints all the objects by iterating through the list. Since Program 2 and 3 were very hard for some, I decided to make Program 4 much easier. If you like to challenge yourself, please do the challenge extra credit partition. __str__ methods in the classes:

? The __str__ method in Pet class returns the pet details: ID, name, symptoms

? The __str__ methods of the subclasses return the pet type plus the pet details.

image text in transcribedimage text in transcribedimage text in transcribed
Sample run: > > > %Run 'CSCI 1523 Program 3. py' Cat: P123, Kitty, symptoms= ['Sleep all day', 'Not eating' ] Dog: P124, Boomer, symptoms= ['Pee every hour' ] Fish: P125, Nemo, symptoms= ['Floating', 'Makes bubbles' ] Classes and their methods: class Pet: def _init_(self, pid, name) def get_pid(self) def get_name (self) def get_symptoms(self) def set_pid(self, pid) def set_name (self, name) def add_symptoms (self, symptom_list) def str_(self) class Cat (Pet) : def _init_(self, pid, name) : def str_(self) : class Fish(Pet) : def _init_(self, pid, name) : def _str_(self) : class Dog (Pet) : def init_(self, pid, name) : def str (self) : Print the pets in the list. This relies on_str_methods to work. for p in pet_list: print (p)Challenge: Extra credit option: Write a Pet data program for an animal hospital >>> %Run 'CSCI 1523 Program 3.py' Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:4 There are not pets. Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:1 Enter pet ID :P123 Enter pet name :Kitty Enter pet symptoms (seperate by comma):Not eating, Sleep all day Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:4 Cat: P123, Kitty, symptoms: ['Not eating', ' Sleep all day'] Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice:2 Enter pet ID :P124 Enter pet name :Boomer Enter pet symptoms (seperate by comma):Pee every hour Pet Emergency Hospital. 1) Add a cat 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 3 Enter pet ID : P125 Enter pet name : Nomo Enter pet symptoms (seperate by comma) : Floating, Makes bubbles Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 4 Cat: P123, Kitty, symptoms= ['Not eating', ' Sleep all day' ] Dog: P124, Boomer, symptoms= ['Pee every hour' ] Dog: P125, Nomo, symptoms= ['Floating', ' Makes bubbles' ] Pet Emergency Hospital. 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 5 Enter PID to look up: P125 Pet found PID = P125 Name = Nomo Symptoms = ['Floating', ' Makes bubbles' ] Pet Emer 1) Add a cat 2) Add a dog 3) Add a fish 4) Display all pets 5) Look up a pet by ID 6) exit Choice : 6 > > >

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What are the major sources of competitor intelligence?

Answered: 1 week ago