Package com.coti.tools
Class Esdia
- java.lang.Object
-
- com.coti.tools.Esdia
-
public class Esdia extends java.lang.Object
Class Esdia offers methods that make it easy to read numeric and alphanumeric
values from the keyboard while showing a prompt; errors are signalled
and indeed it is possible to read only non-empty strings.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Scanner
SC
This class offers a number of static methods that simplify the construction of text-based programs.
-
Constructor Summary
Constructors Constructor Description Esdia()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isValidPath(java.lang.String possiblePath)
This method finds out whether a path is validstatic double
readDouble(java.lang.String prompt)
This method gives back a double after prompting with promptstatic double
readDouble(java.lang.String prompt, double min, double max)
This method gives back a double between min and max after prompting with promptstatic float
readFloat(java.lang.String prompt)
This method gives back a float after promptingstatic float
readFloat(java.lang.String prompt, float min, float max)
This method gives back a float between min and max after prompting with promptstatic int
readInt(java.lang.String prompt)
This method gives back an intstatic int
readInt(java.lang.String prompt, int min, int max)
This method give back an int between min and max after prompting with promptstatic java.nio.file.Path
readPathFromKeyboard(java.lang.String prompt)
This method prompts for a path and gives it back only if validstatic java.lang.String
readString(java.lang.String prompt)
This methos gives back a string after prompting with promptstatic java.lang.String
readString(java.lang.String prompt, java.lang.String[] options)
This method gives back on of the options passed in the second argument after prompting with the firststatic java.lang.String
readString(java.lang.String prompt, java.lang.String op1, java.lang.String op2)
This method give back either op1 or op2 after prompting with promptstatic java.lang.String
readString_ne(java.lang.String prompt)
This methos gives back a non-empty string after promting with promptstatic boolean
yesOrNo(java.lang.String prompt)
This method prompts for a boolean, allowing only "y" or "n" as input
-
-
-
Method Detail
-
readFloat
public static float readFloat(java.lang.String prompt)
This method gives back a float after prompting- Parameters:
prompt
- - this String is shown when asking for into- Returns:
- - the floating point number required by the user
-
readFloat
public static float readFloat(java.lang.String prompt, float min, float max)
This method gives back a float between min and max after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for infomin
- - The minimum value admitted for this numbermax
- - The maximum value admitted for this number- Returns:
- - a float number between min and max
-
readDouble
public static double readDouble(java.lang.String prompt)
This method gives back a double after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for info- Returns:
- - a double number
-
readDouble
public static double readDouble(java.lang.String prompt, double min, double max)
This method gives back a double between min and max after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for infomin
- - The minimum value admitted for this numbermax
- - The maximum value admitted for this number- Returns:
- the double value entered by the user, after validation
-
readInt
public static int readInt(java.lang.String prompt)
This method gives back an int- Parameters:
prompt
- - This string is shown when asking for info- Returns:
- - An int number
-
readInt
public static int readInt(java.lang.String prompt, int min, int max)
This method give back an int between min and max after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for intomin
- - The minimum value admitted for this numbermax
- - The maximum value admitted for this number- Returns:
- - An int number between min and max
-
readString
public static java.lang.String readString(java.lang.String prompt)
This methos gives back a string after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for into- Returns:
- - A String (which could be empty)
-
readString_ne
public static java.lang.String readString_ne(java.lang.String prompt)
This methos gives back a non-empty string after promting with prompt- Parameters:
prompt
- - This string is shown when asking for into- Returns:
- - A String, which cannot be empty
-
readString
public static java.lang.String readString(java.lang.String prompt, java.lang.String op1, java.lang.String op2)
This method give back either op1 or op2 after prompting with prompt- Parameters:
prompt
- - This string is shown when asking for intoop1
- - One of the two admitted value as an answerop2
- - The other value admitted as an answer- Returns:
- - Either op1 or op2
-
readString
public static java.lang.String readString(java.lang.String prompt, java.lang.String[] options)
This method gives back on of the options passed in the second argument after prompting with the first- Parameters:
prompt
- - This string is shown when asking for intooptions
- - A String[] that contains the list of possible answers- Returns:
- - The String entered as answer (which is one of the options)
-
yesOrNo
public static boolean yesOrNo(java.lang.String prompt)
This method prompts for a boolean, allowing only "y" or "n" as input- Parameters:
prompt
- The prompt to be shown- Returns:
- - true if y, false if n
-
isValidPath
public static boolean isValidPath(java.lang.String possiblePath)
This method finds out whether a path is valid- Parameters:
possiblePath
- String checked for validity as a Path- Returns:
- - true if path is valid
-
readPathFromKeyboard
public static java.nio.file.Path readPathFromKeyboard(java.lang.String prompt)
This method prompts for a path and gives it back only if valid- Parameters:
prompt
- shown before waiting for a path- Returns:
- the Path to the given object, after entering a valid String
-
-