/**
* Player color in a game of Chess: either white or black.
*/
public enum Color {
WHITE,
BLACK,
;
public Color getOpposite() {
return this == WHITE ? BLACK : WHITE;
}
public boolean isWhite() {
return this == WHITE;
}
public boolean isBlack() {
return this == BLACK;
}
@Override
public String toString() {
return isWhite() ? "W" : "B";
}
public static void main(String[] args){
String str = "black";
Color c1 = Color.valueOf(str.toUpperCase());
Color c2 = Color.valueOf("white".toUpperCase());
System.out.println("c = "+ c1 + " c = "+ c2);
}
}