Question
Polymorphism An animal shelter holds only dogs and cats, and operates on a strictly first in, first out basis. People must adopt either the oldest
Polymorphism
An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat. Assume each animal has a unique name and thus you don't need to worry. You need to use at most O(n) storage and O(1) for all operations, wherenis the total number of animals in the shelter. Your program should read all ta*.dat in the same directory as your p10.py or p10.ipynb, and generate output for each ta*.dat as the example below. You should use classes for dogs and cats. You need handle whitespace as the whitespace convention and handle errors as always.
Example Input and Output (as comments below) in chronological order:
enqueue(dog, Bark)# put the dog named Bark to shelter
enqueue(cat, Mimi)# put the cat named Mimi to shelter
enqueue(cat, Tiger)# put the cat named Tiger to shelter
dequeue(cat)# the cat named Mimi is adopted
dequeue()# the dog named Bark is adopted
dequeue(dog)# no dog left to be adopted
enqueue(dog, Bark)# put the dog named Bark to shelter
dequeue(dog)# the dog named Bark is adopted
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