Java Reference
In-Depth Information
2 This class encapsulates a work order with a priority.
3 */
4 public class WorkOrder implements Comparable
5 {
6 /**
7 Constructs a work order with a given priority and description.
8 @param aPriority the priority of this work order
9 @param aDescription the description of this work order
10 */
11 public WorkOrder( int aPriority, String
aDescription)
12 {
13 priority = aPriority;
14 description = aDescription;
15 }
16
17 public String toString()
18 {
19 return Ðpriority=Ñ + priority + Ð,
description=Ñ + description;
20 }
21
22 public int compareTo(Object otherObject)
23 {
24 WorkOrder other = (WorkOrder)
otherObject;
25 if (priority < other.priority) return -1 ;
26 if (priority > other.priority) return 1 ;
27 return 0 ;
28 }
29
30 private int priority;
31 private String description;
32 }
750
751
Output
priority=1, description=Fix broken sink
priority=2, description=Order cleaning supplies
priority=3, description=Shampoo carpets
priority=6, description=Replace light bulb
priority=7, description=Empty trash
Search WWH ::




Custom Search