QUESTION

In Java

class Dinosaur has

a static int variable dinoCounter set initially to 1.

a String variable dinoName

an int variable dinoWeight

It has two constructors.

The default constructor sets dinoName to “Barney”

The second constructor:

Accepts an int parameter with the weight of the dinosaur.

Calls the mutator for dinoWeight with the input of the constructor.

Sets dinoName to the concatenation of “DINO” and dinoCounter

Increments dinoCounter by one.

Has accessor and mutator methods for dinoWeight.

Has a toString method that returns a String that produces a line of output as seen in the sample output below.

class ComparatorDinosaur implements the Comparator for Dinosaur

Comparator is simply based on the lower weight preceding the higher weight

Don’t forget the necessary import statement

class PrioritizedDinos

This class contains the main program.

This class creates a PriorityQueue dinoQueue with ordering based on the ComparatorDinosaur Comparator class.

Create a Random object based on a seed of 2.

Do the following ten times

Create a Dinosaurs each with a weight of from 50,000 to 150,000, using the Random object to generate the weight,

Place the Dinosaur object into the dinoQueue

While the dinoQueue is not empty

Remove the highest priority Dinosaur from the dinoQueue and print out its characteristics

Public Answer

M2IEK7 The First Answerer