Getting Array Input - Sam36502/SimpleTUI GitHub Wiki

Setup

All input requires the input scanner to be open. For more info see Input Setup.

Integer Array

There are two ways to get an array. If you know how many values you need to get, then you should use ArrayInput.getIntArray(size). The user will be prompted with a visual representation of the array, showing which position they are currently setting. Once the whole array has been received, they are asked to confirm the contents of the array. If they confirm, the array is returned; otherwise, the user may enter all the values again. Also note, the screen is "cleared" after every prompt. See Output for more info about screen clearing.

Example:

ArrayInput.getIntArray(3);

[#][ ][ ]
Enter the value of the selected cell.
--> 1

[1][#][ ]
Enter the value of the selected cell.
--> 2

[1][2][#]
Enter the value of the selected cell.
--> 3

[1][2][#]
Is this correct?
(y/n) --> y
// Array {1, 2, 3} is returned

If no size is set for the array, the user will simply be prompted to enter how large it should be.

Example:

ArrayInput.getIntArray();

How many values do you want to enter?
--> 3

[#][ ][ ]
Enter the value of the selected cell.
-->
// This works same as above.

Double Array

Double array input works exactly the same as integer input, except you can enter decimal numbers.

Example:

ArrayInput.getDoubleArray(); // Can also be passed a size

How many values do you want to enter?
--> 3

[#][ ][ ]
Enter the value of the selected cell.
--> 0.99999

[0.99999][#][ ]
Enter the value of the selected cell.
--> 3.14159

[0.99999][3.14159][#]
Enter the value of the selected cell.
--> 399.99


[0.99999][3.14159][399.99]
Is this correct?
(y/n) --> y
// Array {0.99999, 3.14159, 399.99} is returned.

String Array

Once again, the string array input works almost identically to the double and integer array inputs.

Example:

ArrayInput.getStringArray(); // Can also be passed a size

How many values do you want to enter?
--> 3

[#][ ][ ]
Enter the value of the selected cell.
--> Hello

[Hello][#][ ]
Enter the value of the selected cell.
--> World!

[Hello][World!][#]
Enter the value of the selected cell.
--> How are you?


[Hello][World!][How are you?]
Is this correct?
(y/n) --> y
// Array {"Hello", "World!", "How are you?"} is returned.