Question
Use the LinkedList class to simulate a queue, and use the addLast method to simulate the enqueue, and the removeFirst method to simulate the dequeue
Use the LinkedList class to simulate a queue, and use the addLast method to simulate the enqueue, and the removeFirst method to simulate the dequeue method for a Queue. Remember to use FIFO.
Create 3 queues, one called Animal Shelter, another called Cats, and another called Dogs. Use the following menu-driven application: 1. Donate a Cat 2. Donate a Dog 3. Adopt a Cat 4. Adopt a Dog 5. Adopt Oldest Pet 6. Exit
Create a Pet class that will be instantiated with the values in the following attributes: String name, int dateOfBirth //yyyymmdd format, String species.
Note: The Dog queue and Cat queue are "regular" queues, and the Animal Shelter queue is a Priority Queue, where the priority is based upon the dateOfBirth of the pet. Theolder the pet, the higher its priority.
Each time a person donates a cat or dog, ask for the name of the pet, the species, and the date of birth, and create a new Pet object. Then, add the Pet object to both its species queue and the general Animal Shelter queue. When a person selects to adopt a specific species pet, remove the first pet object from the appropriate species queue, and also from the Animal Shelter queue. Take care to find the pet in the Animal queue, and remove it, but put back all the others that follow it, in the same order you found them (hint: You may need to create a new queue, removing the dog or cat that needs to be dequeued, and keeping all the rest. Once the new queue is created, point the old queue to the new queue.)
When a person comes in to adopt the oldest pet in the shelter, then process the Animal Shelter as a PriorityQueue, where the pet's date of birth is the attribute used to retrieve the oldest pet (hint: Pet class should implement Comparable, and should define a compareTo method that would sort in ascending date-of-birth order. ) So, when you dequeue the Animal Shelter as a Priority Queue, you will automatically get the Pet with the earliest/oldest date of birth first . Then, after removing the oldest pet object from the animal shelter, then dequeue it from the appropriate species queue (will have to do a sequential search in the the appropriate queue, according to the Pet object's species attribute. See hint above for keeping the exact order in the queue).
Create 3 global variables that represent the 3 queues for dogs, cats, and animal shelter (Priority Queue based on date-of-birth of pet). In the driver class, create the following methods that will be called from main, according to the menu option selected:
1. enqueueCats() 2. enqueueDogs() 3. dequeueCats() 4. dequeueDogs() 5. enqueueAnimals() 6. dequeueAnimals()
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