Question: Use Geometric Objects to create Priority Queue. Main should have add at least 3 Geometric objects and print from Priority Queue. Send me the final

Use Geometric Objects to create Priority Queue. Main should have add at least 3 Geometric objects and print from Priority Queue. Send me the final executable code.

//GEOMETRIC OBJECT//

public class GeometricObject { private String color = " white "; private boolean filled; private java.util.Date dateCreated;

public GeometricObject() { dateCreated = new java.util.Date(); }

public GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }

public String getColor() { return color; }

public void setColor(String color) { this.color = color; }

public boolean isFilled() { return filled; }

public void setFilled(boolean filled) { this.filled = filled; }

public java.util.Date getDateCreated() { return dateCreated; }

public String toString() { return "Created on " + dateCreated + " color: " + color + " and filled "; } }

//PRIORITY QUEUE TEST//

import java.util.Iterator; import java.util.PriorityQueue; import java.util.Queue; public class PriorityQueueTest { public static void main(String args[]){ PriorityQueue GeoQueue = new PriorityQueue(); //Add objects to the PriorityQueue . GeoQueue.add(new Circle(0.5)); GeoQueue.add(new Square(2)); GeoQueue.add(new Square(5)); GeoQueue.add(new Square(1)); System.out.println("GeoQueue elements using Priority Queue method:"); while (GeoQueue.size() > 0) System.out.println(GeoQueue.poll()); //Create PriorityQueue object. Queue priorityQueue = new PriorityQueue(); //Add objects to the PriorityQueue . priorityQueue.add("Gourav"); priorityQueue.add("Neeraj"); priorityQueue.add("Deepak"); priorityQueue.add("Mohan"); priorityQueue.add("Parmender"); //Print the PriorityQueue object. System.out.println("HasPriorityQueue elements:"); System.out.println(priorityQueue); //Print the PriorityQueue elements using iterator. Iterator iterator1=priorityQueue.iterator(); System.out.println("PriorityQueue elements " + "using iterator:"); while(iterator1.hasNext()){ System.out.println(iterator1.next()); } //Print the head element of the PriorityQueue if (priorityQueue.peek() != null) { System.out.println("Head element: " + priorityQueue.element()); System.out.println("Head element: " + priorityQueue.peek()); } //Remove the head element of the PriorityQueue priorityQueue.poll(); priorityQueue.remove(); //Print the PriorityQueue object. System.out.println("HasPriorityQueue elements " + "after manipulation:"); System.out.println(priorityQueue); //Print the PriorityQueue elements using iterator. Iterator iterator2=priorityQueue.iterator(); System.out.println("PriorityQueue elements after " + "manipulation using iterator:"); while(iterator2.hasNext()){ System.out.println(iterator2.next()); } } }

//PriorityQueueTestwithComparator//

package ProrityQueueComparator; import java.util.PriorityQueue; import java.util.Queue; public class PriorityQueueTestwithComparator { public static void main(String args[]){ PriorityQueue GeoQueue = new PriorityQueue(5,new GeometricObjectComparator()); //Add objects to the PriorityQueue . GeoQueue.add(new Circle(0.5)); GeoQueue.add(new Square(2)); GeoQueue.add(new Square(5)); GeoQueue.add(new Square(1)); System.out.println("GeoQueue elements using Priority Queue method:"); while (GeoQueue.size() > 0) System.out.println(GeoQueue.poll()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!