Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello. I need to make a program in Java using Queue, Priority Queue, and Stacks. The Instructions are the following: Use the LinkedList class to

Hello. I need to make a program in Java using Queue, Priority Queue, and Stacks. The Instructions are the following:

Use the LinkedList class to simulate a queue, and use the add method to simulate the enqueue, and the remove method to simulatethe dequeue method for a Queue.Remember to useFIFO.

Create 3 queues, one called Animal Shelter, another called Cats, and another called Dogs.Use the following menu-driven application:

0.Add New Microchips

1.Donate a Cat

2.Donate a Dog

3.Adopt a Cat

4.Adopt a Dog

5.Adopt Oldest Pet

6. Exit

I need to make Pet class that will be instantiated with the values in the following attributes:String name, int dateOfBirth //yyyymmdd format, String species, Long microchipNumber.

Note:The Dog queue and Cat queue are "regular" queues, and the Animal Shelter queue is aPriority Queue, where the priority is based upon the dateOfBirth of the pet.Theolder the pet, thehigherits priority.See the attached .zip file for examples of a PriorityQueue.

Each week,on Monday beforethe Animal Shelter opens, an administrator of the Animal Shelter adds more microchips to thestack of microchips, so that there will be enough microchips to put in any animal that is donated into the shelter that week.To simulate this, you will make a menu option 0, which willgenerate 100 microchip long objects,and place them into astack of microchips.Those microchip objects will be generated by using the System.nanotime() method.

Each time a persondonatesa cat or dog, ask for the name of the pet, the species, and the date of birth, and pop the microchip stack toget a chip to put in the pet. Make new Pet object.Then, add the Pet object to both its specificspeciesqueue, and the generalAnimal Shelterqueue.If the stack of microchips is empty, give an error message to the user,statingthe pet cannot be donated because there are no microchips left.Ask the user to press option 0 to get more microchips.

When a person selects toadopta 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 Shelter queue, and remove it, but put back all the others that follow it, in thesame orderyou found them (hint:Youmay need to make 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.)

Whena person comes in to adopt theoldest pet in the shelter, then process the Animal Shelter as aPriorityQueue, 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 compareTomethod 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 birthfirst .Then, afterremoving the oldest pet object from the animal shelter, thendequeue it from the appropriate species queue (will have to make sequential search in the the appropriate queue, according to the Pet object's species attribute. Seehint abovefor keeping the exact order in the queue).

Create 4 global variables that represent the 3 queues for dogs, cats, and animal shelter (Priority Queue based on date-of-birth of pet), and the stack for the microchips.Create methods that can be called multiple times to accomplish all of the menu options.Thenames of the methods should be:

enqueueCat(),enqueueDog(),dequeueCat(),dequeueDog(),enqueueAnimal(), dequeueAnimal(), pushMicroChip(), popMicroChip()

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