Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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"));

}
}

Java, Programming

  • Category:- Java
  • Reference No.:- M92400200
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As