Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this compliant solution, enum constants are explicitly associated with the corresponding integer values for the number of carbon atoms they contain. ThusConsequently, the ordinal() method is no longer required in knowing the number of carbon atoms for each value.  ( Different enum constants may be associated with the same value, as shown for HEXANE and BENZENE. 

Code Block
bgColor#ccccff
enum Hydrocarbon {
  METHANE(1), ETHANE(2), PROPANE(3), BUTANE(4), PENTANE(5),
  HEXANE(6), BENZENE(6), HEPTANE(7), OCTANE(8), NONANE(9), DECANE(10);

  private final int numberOfCarbons;

  Hydrocarbon(int carbons) { this.numberOfCarbons = carbons; }

  public int getNumberOfCarbons() {
    return numberOfCarbons;
  }
}

...