
Practice 70 Java Enum Types Programming Questions
Q1. Write a Java program to define an enum `Day` with the days of the week and print all the days.
Expected Output:
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
Q2. Write a Java program to create an enum `Month` for all the months of the year and display the number of months in a year.
Expected Output:
12
Q3. Write a Java program to demonstrate the usage of `values()` method in an enum `Color` with values RED, GREEN, BLUE.
Expected Output:
RED
GREEN
BLUE
Q4. Write a Java program to create an enum `Season` with values WINTER, SPRING, SUMMER, and FALL, and print the season name along with its ordinal value.
Expected Output:
WINTER 0
SPRING 1
SUMMER 2
FALL 3
Q5. Write a Java program to compare two enum values of type `TrafficLight` using `compareTo()` method.
Input:
Enum1: RED
Enum2: GREEN
Expected Output:
-1
Q6. Write a Java program to print the name of an enum constant from its string value using `valueOf()` method.
Input:
Enter color name: BLUE
Expected Output:
BLUE
Q7. Write a Java program to get the ordinal value of an enum constant `CarType` with values SEDAN, SUV, TRUCK.
Input:
Enter car type: SUV
Expected Output:
1
Q8. Write a Java program to implement an enum `Priority` with values LOW, MEDIUM, and HIGH. Print the enum constants and their ordinal values.
Expected Output:
LOW 0
MEDIUM 1
HIGH 2
Q9. Write a Java program to define an enum `Status` with values PENDING, IN_PROGRESS, COMPLETED and display the status.
Expected Output:
PENDING
IN_PROGRESS
COMPLETED
Q10. Write a Java program to display the enum constant in uppercase using `toString()` method for enum `Day`.
Input:
Enter day: Monday
Expected Output:
MONDAY
Q11. Write a Java program to create an enum `WeekDay` with values MONDAY, TUESDAY, WEDNESDAY and check if a specific day is a weekend.
Input:
Enter day: MONDAY
Expected Output:
MONDAY is not a weekend.
Q12. Write a Java program to demonstrate the use of `name()` method in enum `Fruit` with values APPLE, BANANA, ORANGE.
Input:
Enter fruit name: BANANA
Expected Output:
BANANA
Q13. Write a Java program to create an enum `AccessLevel` with values GUEST, USER, ADMIN and check if a user has admin access.
Input:
Enter access level: USER
Expected Output:
USER does not have admin access.
Q14. Write a Java program to define an enum `DaysOfWeek` and get the value of a specific day using `ordinal()`.
Input:
Enter day: FRIDAY
Expected Output:
Ordinal of FRIDAY: 5
Q15. Write a Java program to use enum constants in a switch case with `Day` values to print the corresponding day message.
Input:
Enter day: SATURDAY
Expected Output:
It's a weekend!
Q16. Write a Java program to create an enum `Month` and print the month’s number for the given month name.
Input:
Enter month: JULY
Expected Output:
7
Q17. Write a Java program to demonstrate the use of `EnumSet` to store enum constants and print them.
Expected Output:
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
Q18. Write a Java program to check if a given string corresponds to a valid enum constant using `valueOf()` for enum `Direction`.
Input:
Enter direction: EAST
Expected Output:
EAST is a valid enum constant.
Q19. Write a Java program to create an enum `Gender` with values MALE and FEMALE, and check if a given gender is valid.
Input:
Enter gender: MALE
Expected Output:
MALE is valid.
Q20. Write a Java program to implement an enum `Season` with values WINTER, SPRING, SUMMER, and AUTUMN and print the current season.
Expected Output:
Current season: WINTER
Q21. Write a Java program to use an enum `Month` to check if a month is in the first quarter of the year.
Input:
Enter month: FEBRUARY
Expected Output:
FEBRUARY is in the first quarter of the year.
Q22. Write a Java program to create an enum `Direction` with values NORTH, EAST, SOUTH, WEST and check if the entered direction is valid.
Input:
Enter direction: WEST
Expected Output:
WEST is a valid direction.
Q23. Write a Java program to define an enum `Days` and print a message based on the day.
Input:
Enter day: THURSDAY
Expected Output:
It's a weekday.
Q24. Write a Java program to demonstrate the use of `values()` and `valueOf()` methods for an enum `GameStatus`.
Input:
Enter game status: PLAYING
Expected Output:
PLAYING
Q25. Write a Java program to define an enum `VehicleType` with values CAR, MOTORCYCLE, BICYCLE and print all vehicle types.
Expected Output:
CAR
MOTORCYCLE
BICYCLE
Q26. Write a Java program to demonstrate the use of enums in a loop to display enum constants for `TrafficLight`.
Expected Output:
RED
GREEN
YELLOW
Q27. Write a Java program to create an enum `Grade` with values A, B, C, D, F and check the grade status.
Input:
Enter grade: A
Expected Output:
Excellent
Q28. Write a Java program to implement a program that uses an enum `TicketType` to assign prices.
Input:
Enter ticket type: VIP
Expected Output:
Price: $100
Q29. Write a Java program to define an enum `Week` with values MONDAY to SUNDAY and find if a specific day is a weekend.
Input:
Enter day: SUNDAY
Expected Output:
SUNDAY is a weekend.
Q30. Write a Java program to create an enum `TrafficLight` and check if a specific light means stop or go.
Input:
Enter traffic light color: RED
Expected Output:
STOP
Q31. Write a Java program to use an enum `Company` with values GOOGLE, MICROSOFT, APPLE and print the company names.
Expected Output:
GOOGLE
MICROSOFT
APPLE
Q32. Write a Java program to create an enum `BookCategory` and check if the entered category is a valid enum constant.
Input:
Enter category: SCIENCE
Expected Output:
SCIENCE is a valid category.
Q33. Write a Java program to demonstrate enum method `ordinal()` to get the position of a specific enum constant.
Input:
Enter day: FRIDAY
Expected Output:
5
Q34. Write a Java program to define an enum `Pet` with values DOG, CAT, BIRD and check the pet type.
Input:
Enter pet: CAT
Expected Output:
You have a CAT as a pet.
Q35. Write a Java program to create an enum `VehicleType` and find the number of wheels for each type of vehicle.
Input:
Enter vehicle type: CAR
Expected Output:
4
Q36. Write a Java program to use an enum `Plan` with values BASIC, PREMIUM, ULTIMATE and find the plan description.
Input:
Enter plan type: PREMIUM
Expected Output:
Premium plan includes all features.
Q37. Write a Java program to create an enum `ErrorType` with values NETWORK_ERROR, DATABASE_ERROR and check the error type.
Input:
Enter error type: DATABASE_ERROR
Expected Output:
DATABASE_ERROR occurred.
Q38. Write a Java program to create an enum `EmployeeRole` with values MANAGER, DEVELOPER, HR and print the role name.
Expected Output:
MANAGER
DEVELOPER
HR
Q39. Write a Java program to define an enum `Month` and check the number of days in a given month.
Input:
Enter month: FEBRUARY
Expected Output:
28 or 29 days
Q40. Write a Java program to define an enum `TransactionStatus` with values SUCCESS, FAILURE, PENDING and print the status.
Expected Output:
SUCCESS
FAILURE
PENDING
Q41. Write a Java program to define an enum `CarModel` with values SEDAN, SUV, and COUPE and display the model's name and price.
Input:
Enter car model: SUV
Expected Output:
SUV - $30,000
Q42. Write a Java program to create an enum `OrderStatus` with values PENDING, SHIPPED, and DELIVERED and print the current order status.
Input:
Enter order status: SHIPPED
Expected Output:
SHIPPED
Q43. Write a Java program to use enum `UserRole` with values ADMIN, MODERATOR, and USER and check the permissions based on role.
Input:
Enter user role: MODERATOR
Expected Output:
Moderator has limited permissions.
Q44. Write a Java program to define an enum `Size` with values SMALL, MEDIUM, LARGE and display the selected size.
Input:
Enter size: LARGE
Expected Output:
LARGE
Q45. Write a Java program to use enum `PaymentMethod` with values CREDIT_CARD, DEBIT_CARD, PAYPAL and print the available payment methods.
Expected Output:
CREDIT_CARD
DEBIT_CARD
PAYPAL
Q46. Write a Java program to create an enum `MovieGenre` with values ACTION, DRAMA, COMEDY, and HORROR and check the movie genre.
Input:
Enter movie genre: COMEDY
Expected Output:
COMEDY is a popular genre.
Q47. Write a Java program to create an enum `FileExtension` with values TXT, PDF, DOCX and check the file extension for a document.
Input:
Enter file extension: PDF
Expected Output:
PDF is a document format.
Q48. Write a Java program to define an enum `Temperature` with values HOT, WARM, COOL, and COLD and print the temperature description.
Input:
Enter temperature: HOT
Expected Output:
It's hot outside.
Q49. Write a Java program to create an enum `Month` with values JANUARY to DECEMBER and print the total number of months.
Expected Output:
12
Q50. Write a Java program to use an enum `Day` with values MONDAY to SUNDAY and display if a day is a weekday or weekend.
Input:
Enter day: MONDAY
Expected Output:
MONDAY is a weekday.
Q51. Write a Java program to create an enum `WeekDay` with values MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY and check if a day is part of the workweek.
Input:
Enter day: FRIDAY
Expected Output:
FRIDAY is part of the workweek.
Q52. Write a Java program to define an enum `VehicleType` with values CAR, MOTORCYCLE, and TRUCK and check the fuel type for each vehicle.
Input:
Enter vehicle type: TRUCK
Expected Output:
TRUCK uses diesel fuel.
Q53. Write a Java program to create an enum `Language` with values JAVA, PYTHON, C, and check if the entered language is popular.
Input:
Enter language: PYTHON
Expected Output:
PYTHON is a popular programming language.
Q54. Write a Java program to define an enum `ShippingMethod` with values STANDARD, EXPRESS, and OVERNIGHT and display the delivery time.
Input:
Enter shipping method: EXPRESS
Expected Output:
EXPRESS will deliver in 2-3 business days.
Q55. Write a Java program to use an enum `WeekDay` with values MONDAY to SUNDAY and check if a day is a weekend or workday.
Input:
Enter day: SATURDAY
Expected Output:
SATURDAY is a weekend.
Q56. Write a Java program to create an enum `OrderStatus` with values PLACED, DISPATCHED, DELIVERED, and CANCELLED and check if the order is cancelled.
Input:
Enter order status: CANCELLED
Expected Output:
Order is cancelled.
Q57. Write a Java program to define an enum `Size` with values SMALL, MEDIUM, and LARGE and calculate the area for each size.
Input:
Enter size: MEDIUM
Expected Output:
MEDIUM size area: 25 square units
Q58. Write a Java program to define an enum `TicketType` with values REGULAR, VIP, and PREMIUM and print the ticket price.
Input:
Enter ticket type: VIP
Expected Output:
VIP ticket price: $100
Q59. Write a Java program to create an enum `Season` with values WINTER, SPRING, SUMMER, and AUTUMN and check the current season.
Input:
Enter season: SPRING
Expected Output:
SPRING is a season of renewal.
Q60. Write a Java program to define an enum `Fruit` with values APPLE, BANANA, and CHERRY and check if the entered fruit is available.
Input:
Enter fruit: BANANA
Expected Output:
BANANA is available.
Q61. Write a Java program to use an enum `AccessLevel` with values ADMIN, MODERATOR, and USER and check the permissions for each access level.
Input:
Enter access level: USER
Expected Output:
USER has limited permissions.
Q62. Write a Java program to define an enum `UserRole` with values USER, MODERATOR, and ADMIN and print the permissions based on the role.
Input:
Enter user role: ADMIN
Expected Output:
ADMIN has full permissions.
Q63. Write a Java program to create an enum `Season` with values WINTER, SPRING, SUMMER, and AUTUMN and display the weather for each season.
Input:
Enter season: SUMMER
Expected Output:
SUMMER is hot.
Q64. Write a Java program to create an enum `PaymentType` with values CREDIT_CARD, PAYPAL, and CASH and display the available payment types.
Expected Output:
CREDIT_CARD
PAYPAL
CASH
Q65. Write a Java program to define an enum `UserAccess` with values READ, WRITE, EXECUTE and check the permissions.
Input:
Enter access type: WRITE
Expected Output:
WRITE permission granted.
Q66. Write a Java program to define an enum `PriorityLevel` with values LOW, MEDIUM, HIGH and display the corresponding urgency message.
Input:
Enter priority level: MEDIUM
Expected Output:
MEDIUM priority: Process within 2-3 days.
Q67. Write a Java program to use an enum `PaymentStatus` with values PENDING, COMPLETED, and FAILED and check the payment status.
Input:
Enter payment status: COMPLETED
Expected Output:
Payment completed successfully.
Q68. Write a Java program to create an enum `PlanType` with values BASIC, PREMIUM, and ENTERPRISE and display the features for each plan.
Input:
Enter plan type: ENTERPRISE
Expected Output:
ENTERPRISE plan: All premium features included.
Q69. Write a Java program to define an enum `TrafficSignal` with values RED, YELLOW, GREEN and display the appropriate message for each signal.
Input:
Enter signal: YELLOW
Expected Output:
YELLOW: Slow down and prepare to stop.
Q70. Write a Java program to create an enum `CarType` with values SEDAN, SUV, HATCHBACK and display a description for each car type.
Input:
Enter car type: HATCHBACK
Expected Output:
HATCHBACK: Compact and fuel-efficient.