



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




H. Schwartz
COP 3330 – Fall 2006
COP 3330 – Fall 2006
Source: Cohoon and Davidson. Java 5.0 Program Design COP 3330 – Fall 2006
class Wrapper
public Wrapper(T t){ tValue = t; //constructor, t and tValue type are same }
public T get(){ return tValue; //accessor method }
public void set(T t){ tValue = t; //mutator method (changes values) }
public String toString(){ return tValue.toString(); //text representation } }
COP 3330 – Fall 2006
COP 3330 – Fall 2006
COP 3330 – Fall 2006
//assume we have a class ToDoItem which implements comparable: //has a string and priority number, higher = more priority … PriorityQueue
//populate with things to do: tdList.offer(new ToDoItem(“Cut my hair”, 10); tdList.offer(new ToDoItem(“Teach a course”, 2); … //find out next thing to do ToDoItem nextTD = tdList.poll(); while (nextTD != null){ System.out.println(tdList); //calls toString to print item waitForKey(); nextTD = tdList.poll(); }
COP 3330 – Fall 2006