001package edu.pdx.cs410J.j2se15;
002
003import java.util.*;
004
005/**
006 * Demonstrates J2SE's "enumerated type" facility.
007 *
008 * @author David Whitlock
009 * @version $Revision: 1.1 $
010 * @since Summer 2004
011 */
012public class EnumeratedTypes {
013
014  /**
015   * A enumerated type for the days of the week
016   */
017  private enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY,
018                     FRIDAY, SATURDAY }
019
020  /**
021   * Translates a {@link Day} into Spanish
022   */
023  private static String enEspanol(Day day) {
024    switch (day) {
025    case SUNDAY:
026      return "Domingo";
027    case MONDAY:
028      return "Lunes";
029    case TUESDAY:
030      return "Martes";
031    case WEDNESDAY:
032      return "Miercoles";
033    case THURSDAY:
034      return "Jueves";
035    case FRIDAY:
036      return "Viernes";
037    case SATURDAY:
038      return "Sabado";
039    default:
040      String s = "Unknown day: " + day;
041      throw new IllegalArgumentException(s);
042    }
043  }
044
045  /**
046   * Demonstrates enumerated types by adding several to a {@link
047   * SortedSet} and printing them out using their {@link
048   * Enum#toString()} method and in Spanish.
049   */
050  public static void main(String[] args) {
051    SortedSet<Day> set = new TreeSet<Day>();
052    set.add(Day.WEDNESDAY);
053    set.add(Day.MONDAY);
054    set.add(Day.FRIDAY);
055
056    System.out.print("Sorted days: ");
057    for (Day day : set) {
058      System.out.print(day + " ");
059    }
060
061    System.out.print("\nEn espanol: ");
062    for (Day day : set) {
063      System.out.print(enEspanol(day) + " ");
064    }
065    System.out.println("");
066  }
067
068}