This exercise involves creating a class called Entrada
designed to handle various exceptions that may arise when entering data via the keyboard using the Scanner
class in Java.
The class should instantiate a Scanner
object and provide static methods to read different types of data from the keyboard. If an exception occurs while reading the input, the program should handle it and prompt the user again until the correct data is entered.
For example, if a user enters a float with a dot instead of a comma, the program should display "Format error"
, and keep asking for input until the user enters a correctly formatted float.
Each method receives a string containing a message to display to the user (e.g., "Enter your age"
) and returns the correctly entered data.
- Java
Scanner
class- Exception handling (
InputMismatchException
and customException
) - Object-oriented programming principles
- Java Development Kit (JDK) installed.
- A Java-compatible IDE or text editor.
- Basic knowledge of exception handling in Java.
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory: cd project_directory
- Open the project in your preferred IDE.