import java.util.*; public class TreeSetMain { public static void main (String[ ] args) { final String START = "Here is the TreeSet:\n"; final String ADD = "\nAfter adding \"tranquil\", here is the TreeSet:\n"; final String REMOVE = "\nAfter removing \"serene\", here is the TreeSet:\n"; final String REVERSE = "\n\nHere are the scores in decreasing order:\n"; final String SUM = "The sum of the scores is "; TreeSet mySet = new TreeSet(); TreeSet scores = new TreeSet (new Decreasing ()); mySet.add ("happy"); mySet.add ("always"); mySet.add ("yes"); mySet.add ("serene"); System.out.println (START + mySet); if (mySet.add ("happy")) System.out.println ("ooops"); else System.out.println ("\n\"happy\" was not added because it was already there"); mySet.add ("tranquil"); System.out.println (ADD + mySet); System.out.println ("\nsize = " + mySet.size()); if (mySet.contains ("no")) System.out.println ("How did \"no\" get in there?"); else System.out.println ("\n\"no\" was not removed because it was not there"); if (mySet.remove ("serene")) System.out.println (REMOVE + mySet); for (int i = 0; i < 5; i++) scores.add (i); System.out.println (REVERSE + scores); int sum = 0; for (Integer i : scores) sum += i; System.out.println (SUM + sum); } // method main } // class TreeSetMain