enum in JDK 1.5.07
807599Jan 8 2007 — edited Jan 8 2007Hi everyone,
I am new to Java 5, and I am try to recompile the code below in learning the enum, but I got some compiling error such as around the enum. It said that "Syntac error on token "enum" ....
If you have worked through this problem, could you please let me know what is wrong from my code, thanks for your help!
Dung.
--------------------------
package chapter3;
public class EnumTest {
public static void main(String[] argv) {
if ( argv.length < 1 ) {
System.out.println("Usage: java EnumTest [num char]");
System.exit(1);
}
else {
NUM_INFO ni = Enum.valueOf(
NUM_INFO.class, argv[0].toUpperCase());
System.out.println(
"Char : " + ni.getNumChar() + "\n" +
"Value: " + ni.getNumValue()
);
System.out.println("Name of the Num Info : " + ni.name());
}
}
}
enum NUM_INFO {
ONE ('1', 1.0/6.0),
TWO ('2', -2.0/6.0),
THREE ('3', 3.0/6.0),
FOUR ('4', -4.0/6.0),
FIVE ('5', 5.0/6.0),
SIX ('6', -6.0/6.0);
private final char numChar;
private final double numValue;
NUM_INFO(char numChar, double numValue) {
this.numChar = numChar;
this.numValue = numValue;
}
public char getNumChar() {
return this.numChar;
}
public double getNumValue() {
return this.numValue;
}
}