Enums – Exercises
Quiz Summary
0 of 10 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
-
Unfortunately, your results in the simulator were not up to the desired standards. 😔
However, take advantage of your unlimited access and continue to practice.
Remember, persistence and dedication will lead to mastery. 😎 -
Congratulations! 🎉
You have successfully passed the simulator and are now one step closer to achieving your certification.
We hope you will consider joining us again in your future certification journey.Wishing you the best of luck with the upcoming exam. Keep up the great work! 💪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 10
1. Question
You are designing an application to convert digital device states from ON to OFF and vice-versa.
Use the given enum to write a function that toggles the device state:
-
public enum DeviceState {ON, OFF}
public DeviceState toggleState(DeviceState currentState) {
if (currentState == ) return DeviceState.OFF;
if (currentState == ) return DeviceState.ON;
}
CorrectIncorrect -
-
Question 2 of 10
2. Question
You are working on a project where you need to identify the status of customer support tickets. An Enum named
TicketStatushas been defined as:public Enum TicketStatus { OPEN, IN_PROGRESS, RESOLVED, CLOSED }
Fill in the blank to correctly declare a variable named
currentStatusand initialize it with the valueIN_PROGRESS:-
currentStatus = TicketStatus. ;
CorrectIncorrect -
-
Question 3 of 10
3. Question
For an application that determines types of beverages, an enum
Beveragehas been defined.Based on the given code, complete the command to declare a variable that will store a user’s preferred beverage:
-
public enum Beverage {
COFFEE, TEA, SODA, WATER
}
// Fill in the blank:
usersDrink = Beverage.TEA;
CorrectIncorrect -
-
Question 4 of 10
4. Question
You’re working on an application that tracks weather patterns. The application has defined an enum called
Season.Given this, complete the command to declare a variable that will store a particular season:
-
public enum Season {
SPRING, SUMMER, FALL, WINTER
}
// Fill in the blank below:
currentSeason = Season.FALL;
CorrectIncorrect -
-
Question 5 of 10
5. Question
In an application that determines student grades, you have an enum called
Grade.Complete the following method to return a boolean indicating if a student has passed based on their grade:
-
public enum Grade {
A, B, C, D, F
}
public Boolean hasPassed( studentGrade) {
return studentGrade != Grade.F;
}
CorrectIncorrect -
-
Question 6 of 10
6. Question
You’re developing an application to track employee departments.
Complete the method to determine if an employee belongs to the ‘Finance’ department based on the provided enum:
-
public enum Department {
HR, IT, SALES, FINANCE
}
public Boolean isInFinance( empDepartment) {
return empDepartment == Department.FINANCE;
}
CorrectIncorrect -
-
Question 7 of 10
7. Question
You’re writing a program to manage different genres of books in a library. An enum named
BookGenreis established.Fill in the blank to declare a variable that will store the main genre of a newly added book:
-
public enum BookGenre {
FICTION, NONFICTION, MYSTERY, BIOGRAPHY
}
// Complete the following line:
mainGenre = BookGenre.MYSTERY;
CorrectIncorrect -
-
Question 8 of 10
8. Question
Consider an application that manages different modes of transport. You want to determine if a provided mode of transport is environmentally friendly.
Fill in the blank:
-
public enum TransportMode {
CAR, BUS, BICYCLE, TRAIN
}
public Boolean isEcoFriendly( chosenMode) {
return chosenMode == TransportMode.BICYCLE;
}
CorrectIncorrect -
-
Question 9 of 10
9. Question
You’ve been given a task to declare an
EnumnamedPaymentStatusto represent the different statuses a payment can have in a system, such as ‘Pending’, ‘Completed’, and ‘Failed’. Declare thisEnumand then create a variable namedcurrentStatusand assign it the valueCompleted.Fill in the blanks below:
-
public {
, ,
}
= PaymentStatus. ;
CorrectIncorrect -
-
Question 10 of 10
10. Question
Consider an
EnumnamedUserRolewith the values ‘Admin’, ‘User’, and ‘Guest’. Write a method namedgetDefaultRolewhich should return the default role User from theUserRoleEnum.Fill in the blanks below:
-
public {
, ,
}
public UserRole () {
return UserRole. ;
}
CorrectIncorrect -