Lecture 9 - CS 159 enumerated types
Prof. Alvin Chao
Due this week:
Enumerated Types
Enumerated Types in Java
Design + Implementation
Properties of enum vs. instance
Methods available to enum in Java
Though it is not immediately obvious from the documentation for the Java API, all enumerated types have the following methods "implemented for them".�Static Methods:� - values() returns an array containing all of the objects in the set� - valueOf(String) returns the instance with the specified identifier (or throws IllegalArgumentException)�Non-Static Methods:� - int compareTo(E other) which uses the order of the elements� - boolean equals(E other)� - ordinal() returns the ordinal value of the instance (0-based)� - toString() returns a String representation of the identifier
Example
Example - Initial Encapsulation
Using Initial Encapsulation
Adding Attributes
Adding Methods
Final Design
Using the Month enum
Alternatives to enums