Exercise: Days of the Week

Strengthen your Kotlin skills by creating an enum class representing days of the week with specific properties and functions.

We'll cover the following

Problem statement

Define an enum class named DayOfWeek to represent the days of the week: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY. Organize the enum elements in the order they appear in the week.

The enum should have a primary constructor with two properties:

  • isWeekend (of type Boolean): Indicates whether the day is a weekend day (Saturday or Sunday).

  • dayName (of type String): Contains the full name of the day.

Implement a function named nextDay that takes a day of the week as input and returns the next day in the sequence. For instance, if the input is MONDAY, the function should return TUESDAY.

The actual output when running the provided code should be as follows:

Get hands-on with 1400+ tech skills courses.