import java.util.*; import java.time.*;// Step 1: Create an interface interface AlertDAO UUID addAlert(LocalDateTime time); LocalDateTime getAlert(UUID id);
// Step 2: Implement the interface class MapAlertDAO implements AlertDAO private final Map<UUID, LocalDateTime> alerts = new HashMap<>();
public UUID addAlert(LocalDateTime time) UUID id = UUID.randomUUID(); alerts.put(id, time); return id; public LocalDateTime getAlert(UUID id) return alerts.get(id);// Step 3: Inject via constructor class AlertService private final AlertDAO storage; testdome java questions and answers
public AlertService(AlertDAO dao) // Dependency injection this.storage = dao; public UUID raiseAlert() return storage.addAlert(LocalDateTime.now()); public LocalDateTime getAlertTime(UUID id) return storage.getAlert(id);
The "Aha!" moment: TestDome's grader will run unit tests that mock AlertDAO. The original version fails because you cannot mock MapAlertDAO. The refactored version passes all hidden OOP tests. import java
Sample Question:
Write a thread-safe singleton DatabaseConnection class using double-checked locking.
Prompt: A TrainComposition is built by attaching and detaching wagons from the left and right sides. Implement attachWagonFromLeft, attachWagonFromRight, detachWagonFromLeft, and detachWagonFromRight.
This tests your knowledge of Deque (double-ended queue). Using an ArrayList here fails the performance test for 1 million operations. // Step 2: Implement the interface class MapAlertDAO
Prompt: Implement the uniqueNames method. Given two arrays of strings, return a sorted array containing all unique names.
This is the "Hello World" of TestDome Java. It tests collections, sorting, and null-awareness.
Task:
Write a method that returns true if a string is a palindrome (case-insensitive, ignoring non-alphanumeric characters).
Example:
"A man, a plan, a canal: Panama" → true
