Java Reference
In-Depth Information
Note:
The class
java.sql.Date
The class
Date
in the package
java.sql
of the Java Class Library has a constructor whose
parameter specifies the date as the number of milliseconds since midnight GMT on January
1, 1970. A more convenient way for us to construct a
Date
object is to use the following static
method
valueOf
:
public static
Date valueOf(String s)
Returns a
Date
object whose value is given by a string
s
in the form
yyyy-mm-dd.
For example, the expression
Date.valueOf("2012-02-29")
returns a
Date
object represent-
ing February 29, 2012.
Date
implements the interface
Comparable<Date>
and overrides
toString
.
10.21
We can either add instances of
Assignment
directly to a priority queue or write a simple wrapper
class
AssignmentLog
to organize our assignments. As Figure 10-13 shows,
AssignmentLog
has a
data field
log
, which is an instance of a priority queue that contains the assignments in priority
order. The methods
addProject
,
getNextProject
, and
removeNextProject
manipulate the prior-
ity queue indirectly.
FIGURE 10-13
A diagram of the class
AssignmentLog
AssignmentLog
log
—a priority queue of assignments
addProject(newAssignment)
addProject(courseCode, task, dueDate)
getNextProject()
removeNextProject()
An implementation of
AssignmentLog
appears in Listing 10-6.
LISTING 10-6
The class
AssignmentLog
import
java.sql.Date;
public
class
AssignmentLog
{
private
PriorityQueueInterface<Assignment> log;
public
AssignmentLog()
{
log =
new
PriorityQueue<Assignment>();
}
// end constructor
public
void
addProject(Assignment newAssignment)
{
log.add(newAssignment);
}
// end addProject