-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
In the current implementation, user input is read using Scanner.nextInt() for age and Scanner.nextLine() for name fields in console applications. If the user provides an invalid data type (e.g., entering 'hello' instead of a number for age), the application throws a java.util.InputMismatchException and terminates unexpectedly. This behavior reduces the robustness and user-friendliness of the application. The issue is present in the use cases for age input (expects integer) and name input (expects non-empty string).
Steps to Reproduce
- Run the application.
- When prompted with Enter your age (must be a positive number):, enter a string (e.g., hello) instead of an integer.
- Observe the InputMismatchException and stack trace in the console.
Expected Behavior
The program should validate the input and prompt the user to try again with the correct data type, displaying a clear error message such as "Invalid input. Please enter a valid number for age." The application should not crash.
Metadata
Metadata
Assignees
Labels
No labels