Challenge: Guard Clauses in User Registration
Tâche
Swipe to start coding
Write a method to register a user that uses guard clauses to validate the provided username and password.
- If
usernameis null or empty, immediately throw anArgumentExceptionwith the message "Username cannot be null or empty.". - If
passwordis null or empty, immediately throw anArgumentExceptionwith the message "Password cannot be null or empty.". - If both inputs are valid, return a string in the format "User '
' registered successfully.".
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 4
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Suggested prompts:
Can you explain this in simpler terms?
What are some examples related to this topic?
How does this information apply to real-world situations?
Génial!
Completion taux amélioré à 4.17
Challenge: Guard Clauses in User Registration
Glissez pour afficher le menu
Tâche
Swipe to start coding
Write a method to register a user that uses guard clauses to validate the provided username and password.
- If
usernameis null or empty, immediately throw anArgumentExceptionwith the message "Username cannot be null or empty.". - If
passwordis null or empty, immediately throw anArgumentExceptionwith the message "Password cannot be null or empty.". - If both inputs are valid, return a string in the format "User '
' registered successfully.".
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 4
single