Challenge - 5 Problems
Use Case Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of method call with record use case
What is the output of the following Java code using records to represent a use case?
Java
record User(String name, int age) {} public class Main { public static void main(String[] args) { User user = new User("Alice", 30); System.out.println(user.name() + " is " + user.age() + " years old."); } }
Attempts:
2 left
💡 Hint
Look at how record components are accessed using methods with the same name.
✗ Incorrect
Records automatically create methods with the same name as their components to access values. So user.name() returns "Alice" and user.age() returns 30.
🧠 Conceptual
intermediatePurpose of use cases in software development
Which of the following best describes the main purpose of use cases in software development?
Attempts:
2 left
💡 Hint
Think about how use cases help understand what users want to do with the system.
✗ Incorrect
Use cases describe how users interact with the system to accomplish specific goals, helping developers understand requirements.
🔧 Debug
advancedIdentify the error in this use case implementation
What error will this Java code produce when run?
Java
public class UseCase { private String action; public UseCase(String action) { this.action = action; } public void execute() { System.out.println("Executing " + action); } public static void main(String[] args) { UseCase uc = null; uc.execute(); } }
Attempts:
2 left
💡 Hint
Check what happens when you call a method on a null reference.
✗ Incorrect
Calling a method on a null object reference causes a NullPointerException at runtime.
📝 Syntax
advancedCorrect syntax for defining a use case class with a method
Which option shows the correct syntax to define a Java class named UseCase with a method run that prints "Running use case"?
Attempts:
2 left
💡 Hint
Remember Java method declarations require return type and access modifier is optional but recommended.
✗ Incorrect
Option A correctly declares a public class with a public void method run with proper syntax.
🚀 Application
expertNumber of use case objects created and their output
Consider this Java code creating use case objects. How many objects are created and what is printed?
Java
public class UseCase { private final String name; public UseCase(String name) { this.name = name; } public void execute() { System.out.println("Use case: " + name); } public static void main(String[] args) { UseCase[] cases = new UseCase[3]; for (int i = 0; i < cases.length; i++) { cases[i] = new UseCase("Case" + (i + 1)); } for (UseCase uc : cases) { uc.execute(); } } }
Attempts:
2 left
💡 Hint
Look at the loop creating new UseCase objects and the loop printing them.
✗ Incorrect
The code creates 3 UseCase objects with names Case1, Case2, Case3 and prints each name once.
