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 inputimportlib.Console.Read;// import for writing 1d & 2d arraysimportlib.Console.Write;// import for generating random integersimportlib.Math.Random;
Creating the Objects:
// Object for reading user inputRead read =newRead();// Object for writing 1d & 2d arraysWrite write =newWrite();// Object for generating a random integerRandom rnd =newRandom();
Reading user input:
// Error that will be displayed if the user inputs the wrong data typeStringerror_msg ="Wrong input!"// Reading an integerintuser_input_int = read.nextInt(error_msg);// Reading a bytebyteuser_input_byte = read.nextByte(error_msg);// Reading a shortshortuser_input_short = read.nextShort(error_msg);// Reading a longlonguser_input_long = read.nextLong(error_msg);// Reading a floatfloatuser_input_float = read.nextFloat(error_msg);// Reading a doubledoubleuser_input_double = read.nextDouble(error_msg);// Reading a booleanbooleanuser_input_boolean = read.nextBoolean(error_msg);// Reading an StringStringuser_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 printint[]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 arraywrite.arrayInt1(1d_int_array);// Write 2D int arraywrite.arrayInt2(2d_int_array);
Generating an random intager:
// range for random intintmin =0;intmax =42;// Generate random intintrandomNumber = rnd.rndInt(min, max);