Enum with properties and methods
📖 Scenario: Imagine you are creating a simple app that shows different types of coffee sizes with their prices and descriptions.
🎯 Goal: You will create an enum class in Kotlin that has properties and a method to describe each coffee size.
📋 What You'll Learn
Create an enum class called
CoffeeSize with three entries: SMALL, MEDIUM, and LARGEEach enum entry should have two properties:
price (Double) and description (String)Add a method called
displayInfo() inside the enum that returns a string combining the size name, price, and descriptionPrint the result of calling
displayInfo() on each enum entry💡 Why This Matters
🌍 Real World
Enums with properties and methods are useful to represent fixed sets of related data with extra details, like product sizes, statuses, or categories.
💼 Career
Understanding enums with properties and methods helps in writing clean, organized code in Kotlin, which is valuable for Android development and backend services.
Progress0 / 4 steps