Inputer is located under the directory: "src/com/biziol/Inputer.java"
Once you have made the changes, compile the class
go to the build folder and run this command:
cd bin && jar cvf ../InputerLibrary.jar com/biziol/Inputer.class: this will create the library needed by users.
This library, Inputer, provides a convenient way to read various types of input from the console in Java.
- Place the
InputerLibrary.jarfile into thelibfolder of your Java project. - Import library via
import com.biziol.InputerTo use the Inputer class in your project, import it:
import com.biziol.Inputer;Then, create an instance of the Inputer class:
Inputer inputer = new Inputer();Description: Displays a prompt and reads a line of text from the console.
Parameters:
prompt (String): The prompt to display to the user. Return Value: A String containing the line read from the console, or null if the end of the stream is reached.
Example:
String name = inputer.readLine("Enter your name");
output: Enter your name -->Description: Displays a prompt and reads an integer from the console.
Parameters:
prompt (String): The prompt to display to the user. Return Value: An Integer value, or null if the input is not a valid integer.
Error Handling: If the input is not a valid integer, an error message is printed to System.err.
Example:
Integer age = inputer.readInteger("Enter your age");
output: Enter your age -->Description: Displays a prompt and reads a double from the console.
Parameters:
prompt (String): The prompt to display to the user. Return Value: A Double value, or null if the input is not a valid double.
Error Handling: If the input is not a valid double, an error message is printed to System.err.
Example:
Double price = inputer.readDouble("Enter the price");
output: Enter the price -->Description: Clears the console screen.
Example:
Inputer.clearScreen();The readInteger() and readDouble() methods handle NumberFormatException by printing an error message to System.err and returning null. You should check for null after calling these methods to handle invalid input.