6. |
P2. A Strategy Interface
Modify the test program so that it sorts Rectangle objects:
Rectangle rect1 = new Rectangle(5, 10, 20, 30); Rectangle rect2 = new Rectangle(10, 20, 30, 15); Rectangle rect3 = new Rectangle(20, 30, 45, 10);
list.add(rect1); list.add(rect2); list.add(rect3);
// call the library sort method Collections.sort(list);
// print out the sorted list for (int i = 0; i < list.size(); i++) { Rectangle r = (Rectangle)list.get(i); System.out.println(r.getWidth() + " " + c.getHeight()); }
When you run the program, you will get an error message. What is the error message? What is the reason for the error message?
Answer:
|