Create a listing "Month". It is necessary to determine in the constructor and save the number of days. Add methods to get the previous and next month, as well as a function that returns the season for each month. To provide for the withdrawal of months in Russian. Create a static output function for all months by overriding the toString()
method. Test the enumeration in the test-class main()
function. Help override the toString()
method.
enum Month12 { JANUARY(31), FEBRUARY(28), MARCH(31), APRIL(30), MAY(31), JUNE(30), JULY(31), AUGEST( 31), SEPTEMBER(30), OCTOBER(31), NOVEMBER(30), DECEMBER(31); private Integer days; private Month12(Integer days) { this.days = days; } public Integer getDays() { return days; } public String toString() { switch (this) { case JANUARY: return "Январь"; case FEBRUARY: return "Февраль"; case MARCH: return "Март"; case APRIL: return "Апрель"; case MAY: return "Май"; case JUNE: return "Июнь"; case JULY: return "Июль"; case AUGEST: return "Август"; case SEPTEMBER: return "Сентябрь"; case OCTOBER: return "Октябрь"; case NOVEMBER: return "Ноябрь"; case DECEMBER: return "Декабрь"; } return "not month"; } Month12 next() { Month12 a = values()[(ordinal() + 1) % values().length]; return a; } Month12 before() { Month12 a = values()[(ordinal() - 1 + 12) % values().length]; return a; } public String season() { switch (this) { case JANUARY: case FEBRUARY: case DECEMBER: return "Зима"; case MARCH: case APRIL: case MAY: return "Весна"; case JUNE: case JULY: case AUGEST: return "Лето"; case SEPTEMBER: case OCTOBER: case NOVEMBER: return "Осень"; default: return "not month"; } } } public class Month { public static void main(String[] args) { Month12 a = Month12.JANUARY; System.out.println("Введенный месяц: " + a); System.out.println(a.next()); System.out.println(a.before()); System.out.println(a.season()); } }
toString()
not a static function. / thread - VladD