Question
Learning about enums now. My enum here are the months in the year. I'm going to need to be able to calculate month to month
Learning about enums now. My enum here are the months in the year. I'm going to need to be able to calculate month to month so I needed them to have an ordering (January = 0, December = 11), I'll need to be able to access and print the number of days in a month and I'll need to be able to choose between printing the full (long) month name or an abbreviated (short) version.
I started off doing what I thought would declare my months and add the other data to them, but I'm already getting errors when I test compile. It says Cannot find symbol - variable JAN referring to the shortened version of January and it pops up one of those errors for each month.
Where have I gone wrong? Would really appreciate an explanation as well as correct code as this really seemed right from the 2 explanation examples I saw.
public enum Month { JANUARY(0,31,JAN), FEBRUARY(1,28,FEB), MARCH(2,31,MAR), APRIL(3,30,APR), MAY(4,31,MAY), JUNE(5,30,JUN), JULY(6,31,JUL), AUGUST(7,31,AUG), SEPTEMBER(8,30,SEP), OCTOBER(9,31,OCT), NOVEMBER(10,30,NOV), DECEMBER(11,31,DEC); private int order; private int dayTotals; private String SHORT; private Month(int o, int dT, String SHORT){ order = o; dayTotals = dT; SHORT = SHORT; } /** * Get the number of days in the month. Leap years are not considered. * Ex: January -> 31 * @return the number of days in a month */ public int getLength() { //TODO: Implement me return 0; } /** * Adds numberOfMonths to the current Month and returns what month it will then be. * @param numberOfMonths the number of months to look ahead * @return what month it will be numberOfMonths after the current month */ public Month plus(int numberOfMonths) { //TODO: Implement me return JANUARY; } /** * Return the name of the month in the requested style, either SHORT or default to LONG. For some months, * SHORT may be equal to LONG. * Ex: A SHORT style would return 'Jan' and the LONG style would return 'January' * @param style - the style the month should be returned in * @return the display name of the current month according to the requested style. */ public String getDisplayName(DisplayStyle style) { //TODO: Implement me return ""; } @Override public String toString(){ return name().substring(0,1) + name().substring(1).toLowerCase(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started