Enums

Chapter: More Java 1.5
...Section: Enums

Read the documentation and Google for tutorials about Java's enum (this entered the language with version 1.5). Then you'll know what I mean by:

    enum English {one, two, three, four, five, six, seven, eight, nine,
            ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen,
            seventeen, eighteen, nineteen, twenty;
    }

The natural ordering for this enum is the same as the order in which I specify the entries. Namely one comes before two comes before three, and so on. I can create an array of these enums:

     English[] foo = new English[args.length];
and create a Sort for them via:
     Sort < English > s = new Sort < English > (foo);

Now all you have to do is figure out how to convert commandline arguments into English objects, and your code will run like mine:

java SortEnglish one three five four two
one
two
three
four
five

In the following exercise you are asked, in parts, to "discuss ideas" for a program. You can do exactly that. Or, if you prefer, you can write a program to accomplish the described task.


Exercise 3

  1. Program SortEnglish.java to behave as above.
  2. Discuss ideas for making an improved version of SortEnglish that can handle numbers from one to one-thousand. For the purposes of this exercise we will butcher the English language by requiring hyphens to connect words in compound numbers; thus deal with four-hundred-thirty-seven, not "four hundred thirty seven".
  3. Discuss ideas for removing the need for the hyphens
  4. Discuss ideas for sorting roman numerals so that, for example,
    java SortRoman III I IV XII XLII VI CI
    I III IV VI XII XLII CI
    
  5. Program SortRoman to work for at least
    I II III IV V VI VII VIII IX X
    XI XII XIII XIV XV XVI XVII XVIII XIX XX
    XXI XXII XXIII XXIV XXV XXVI XXVII XXVIII XXIX XXX
    XXXI XXXII XXXIII XXXIV XXXV XXXVI XXXVII XXXVIII XXXIX XL
    XLI XLII XLIII XLIV XLV XLVI XLVII XLVIII IL L
    



rhyspj@gwu.edu