Instalation of Java Library School
• Download the zip file: lib.zip from the page Java Library School• Extract the contents of the folder
• copy the folder lib contained in the zip in to the root of your project
Use of Java Library School
Import the library:
// import for reading user input
import
lib.Console.Read;// import for writing 1d & 2d arrays
import
lib.Console.Write;// import for generating random integers
import
lib.Math.Random;
Creating the Objects:
// Object for reading user input
Read read =new
Read();// Object for writing 1d & 2d arrays
Write write =new
Write();// Object for generating a random integer
Random rnd =new
Random();
Reading user input:
// Error that will be displayed if the user inputs the wrong data type
String
error_msg ="Wrong input!"
// Reading an integer
int
user_input_int = read.nextInt
(error_msg);// Reading a byte
byte
user_input_byte = read.nextByte
(error_msg);// Reading a short
short
user_input_short = read.nextShort
(error_msg);// Reading a long
long
user_input_long = read.nextLong
(error_msg);// Reading a float
float
user_input_float = read.nextFloat
(error_msg);// Reading a double
double
user_input_double = read.nextDouble
(error_msg);// Reading a boolean
boolean
user_input_boolean = read.nextBoolean
(error_msg);// Reading an String
String
user_input_String = read.nextLine
(error_msg);
Printing arrays:
The example below shows only the functions for printing int arrays. For all other functions the naming scheme is the same as for inputs.// Int arrays to print
int[]
1d_int_array = {97
,111
,99
,97
,108
,117
,120
};int[][]
2d_int_array = {{23
,73
,225
}, {59
,53
,25
}, {12
,73
,225
}};// Write 1D int array
write.arrayInt1
(1d_int_array);// Write 2D int array
write.arrayInt2
(2d_int_array);
Generating an random intager:
// range for random int
int
min =0
;int
max =42
;// Generate random int
int
randomNumber = rnd.rndInt
(min, max);