Package sc2002.FCS1.grp2.helpers
Class SuperScanner
Object
SuperScanner
An extension of features for the
Scanner class.
This class allows for more convenient input gathering from users, for types that may be error prone.
For example, when expecting an integer, the user may input something else, such as text.
Here, it will automatically and recursively ask the user until the input given is in correct format.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSuperScanner(Scanner scanner) Construct a SuperScanner to use convenient user input abilities -
Method Summary
Modifier and TypeMethodDescriptionWhere necessary, you can access the associatedScannerobject where necessary.private BooleanPrints the prompt, and then wait for user's input, on same line, expecting a boolean.nextBoolUntilCorrect(String prompt) Get user input that is binary (either true or false).private LocalDatePrints the prompt, and then wait for user's input, on same line, expecting a date, of d/M/yy.nextDateUntilCorrect(String prompt) Get user input of date type, while ensuring format is correct.private intPrints the prompt, and then wait for user's input, on same line, expecting a number.intnextIntUntilCorrect(String prompt) Get input from user until input is a number.intnextIntUntilCorrect(String prompt, int min, int max) Get input from user until input is a number, and falls within boundaries provided.
-
Field Details
-
scanner
Scanner object to be referenced in class.
-
-
Constructor Details
-
SuperScanner
Construct a SuperScanner to use convenient user input abilities- Parameters:
scanner- Scanner to be used to get user input.
-
-
Method Details
-
getScanner
Where necessary, you can access the associatedScannerobject where necessary.- Returns:
- Scanner object.
-
nextIntUntilCorrect
Get input from user until input is a number.- Parameters:
prompt- The prompt to be shown to the user.- Returns:
- integer input by user.
-
nextIntUntilCorrect
Get input from user until input is a number, and falls within boundaries provided. Both min and max parameters are inclusive; All values in between are also treated as accepted.- Parameters:
prompt- The prompt to be shown to the user.min- The minimum value to be accepted. (inclusive)max- The maximum value to be accepted. (inclusive)- Returns:
- The integer that is provided by the user's input.
-
nextDateUntilCorrect
Get user input of date type, while ensuring format is correct. Date format expected should be d/M/yy, where d is day, M is month, and yy is year (2 digits)- Parameters:
prompt- The prompt to be shown to the user.- Returns:
- Date provided by the user.
-
nextBoolUntilCorrect
Get user input that is binary (either true or false). Repeats until user input given is valid. This method accepts a few forms to represent truthness.true:- T
- True
- Yes
- Y
false:- F
- False
- No
- N
- Parameters:
prompt- The prompt to be shown to the user.- Returns:
- boolean representative of user's input.
-
nextInt
Prints the prompt, and then wait for user's input, on same line, expecting a number.- Parameters:
prompt- The prompt associated with the input.- Returns:
- User's input as an integer.
- Throws:
NumberFormatException- When user's input is not an integer.
-
nextDate
Prints the prompt, and then wait for user's input, on same line, expecting a date, of d/M/yy. d/M/yy format is used as that is the date format that the spreadsheet samples given to us are using.- Parameters:
prompt- The prompt associated with the input.- Returns:
- User's input as an date (format: d/M/yy).
- Throws:
DateTimeParseException- When user's input is not a date or of incorrect formatting.
-
nextBool
Prints the prompt, and then wait for user's input, on same line, expecting a boolean. This method employs a very relaxed way of detecting boolean state. Users can input the following, irrespective of case:true:- T
- True
- Yes
- Y
false:- F
- False
- No
- N
- Parameters:
prompt- The prompt associated with the input.- Returns:
- A boolean according to user's input
- Throws:
IllegalArgumentException- When user's input does not fit detectable boolean state.
-