Activity 7: Enum Types¶
Provided Files¶
- Activity Packet
- Example Code – for Model 2
Documentation¶
- java.lang.Enum – methods that all enums have
Model 1 Code¶
Open JShell on your computer. Type (or copy and paste) the following enum definition:
public enum Month {
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC;
}
Then type each line of code below in JShell, one at a time, and record the results.
You only need to record the output to the right of the ==>
symbol.
For example, if JShell outputs $8 ==> true
, then just write true
.
If an error occurs, summarize the error message.
Month m = null;
m = JUN;
m = Month.JUN;
m.toString()
Month spring = Month.MAR;
Month summer = Month.JUN;
m == spring
m == summer
Month.JUL = summer;
m.ordinal()
spring.ordinal()
Month.OCT.ordinal()
m.compareTo(spring)
m.compareTo(Month.OCT)
m = Month.valueOf("Mar");
m = Month.valueOf("MAR");
m == spring
m = Month.valueOf(5);
m = new Month("HEY");
Month[] all = Month.values();
all[0]
all[11]
all[12]