Create an application that uses a priorityqueue

Assignment Help JAVA Programming
Reference no: EM131591487

Create an application that uses a "PriorityQueue" to perform the following

Uses the constructor that receives a "Comparator" object as an argument
Stores 5 "Time1" objects using the "Time1" class shown in Fig. 8.1 on page 317. The class must be modified to implement the "Comparator" interface

Displays the "Universal Time" in priority order
Note: To determine the ordering when implementing the "Comparator" interface, convert the time into seconds (i.e., hours * 3600 + minutes * 60 + seconds), smaller values infer higher priority)

Here is the PriorityQueue class:

import java.util.Comparator;
import java.util.PriorityQueue;

public class PriorityQueueTest
{
public static void main( String[] args )
{
// queue of capacity 5 and a new Comparator
PriorityQueue< Double > queue =
new PriorityQueue< Double >( 5, new DoubleComparator() )

// insert elements to queue
queue.offer( 3.2 );
queue.offer( 9.8 );
queue.offer( 5.4 );

System.out.print( "Polling from queue: " );

// display elements in queue
while ( queue.size() > 0 )
{
System.out.printf( "%.1f ", queue.peek() ); // view top element
queue.poll(); // remove top element
} // end while
} // end main

private static class DoubleComparator implements Comparator< Double >
{
public int compare( Double first, Double second )
{
return -Double.compare( first, second );
} // end method compare
} // end class TimeComparator
} // end class PriorityQueueTest

Here is the Time class in page 317

public class Time1
{
private int hour;
private int minute;
private int second;

public void setTime(int hour, int minute, int second)
{
if (hour < 0 || hour >= 24 || minute < 0 || minute >=60 ||
second < 0 || second >=60)
{
throw new IllegalArgumentException("out of range");
}
this.hour = hour;
this.minute = minute;
this.second = second;
}
public String.format("%02d:%02d:%02d", hour, minute, second);
}
public String to String()
{
return String.format("%d:%02d:%02d %s",((hour == 0 || hour == 12) ? 12 : hour % 12),
minute, second, (hour < 23 ? "AM" : "PM"));

}
}

Reference no: EM131591487

Questions Cloud

Differences between health disparities and health equity : What are the differences between health disparities and health equity? Give examples of the different approaches and philosophies when utilizing these terms.
Discuss about accountability and governance : Copy and phealth care delivery are varied and arise from many different sources, such as the emergence of new technologies, changing patient and workforce.
Promoting a diverse workforce : Then, argue whether or not the intended fairness afforded by affirmative action is relevant to the 21st century, considering that organizations.
What are your thoughts on the ethics of using animals : What are your thoughts on the ethics of using animals for these tests? What guidelines for humane treatment should be followed?
Create an application that uses a priorityqueue : Create an application that uses a PriorityQueue to perform - determine the ordering when implementing the Comparator interface
Create solutions to specific teaching challenges : Choose a topic for them to research and devise engaging learning experiences as a team for them to discover how to find information on that topic.
Components of needs assessment logic : Needs Assesssment and states "the logic of needs assessment can be summarized as a simple equation:
Define instructional design : Define instructional design and describe its purpose. can it be more than 100 words please. References are required.
Understanding of how the human resource function : The objective of this assessment is to demonstrate your understanding of how the human resource function interacts with other functions in the organization.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd