SWE/CS 332 In Class Exercise # 25: Enums and Annotations
November 27, 2017


Consider the following (bad) Java, implementing the "C style" enum pattern:
public class Coins {
   public static final int PENNY = 1;
   public static final int NICKLE = 5;
   public static final int DIME = 10;
   public static final int QUARTER = 25;
  1. Give example code that illustrates a type safety problem with Coins.

  2. What code would you need to turn a nickel into a string? Explain how this could go wrong at runtime.

  3. What code would you need to iterate through the coins?

  4. Would extensions to this particular enum be likely to require recompilation of client code? Explain.

  5. Write a decent Java Enum for coins.

  6. Turn a nickle into a string.

  7. Iterate though the coins.