Site Overlay


Hits: 41

An array is a collection of items of the same data type. The train simulator project employs a number of arrays to represent sets of information such as the gradient profile, the motor characteristics and the train system information. This information is stored in tables. Data tables do contain a number of columns and rows. Arrays too can contain columns and rows this is declared as a two dimensional array or a matrix. An array can be initialized (created) as shown below.

Allocating the array and then filling each entry

int [] gradients = new int [5];

gradients [0] = -100;

gradients [1] = 0;

gradients [2] = 100;

gradients [3] = 75;

gradients [4] = 500;

Note:  int stands for integer in java, the gradient values are integer values.

This simply initialises an array of gradient values called gradients. The size of this array is 5 (the value in the [] brackets). All arrays count starts from zero (0), and not one, so if the size is 5, we expect the count start at 0 and terminate at 4. No more data can be entered after the fifth array value gradients [4].

By increasing the size of the above array from 5 to some finite value, the capacity of the array increases and more data can be entered.

A two dimensional array consists of a rows and columns and this can be declared in the program as:

int [][] current = new int [12][10];  for 12 rows and 10 columns.

To access a particular element in the matrix, two subscripts in separate brackets are specified for example:

current [3][4] = 500; for calling the item in the row 3 and column 4, which initially was zero, and replacing it by the value 500.

So each time we want to look at the item at this position of the matrix, we call the matrix as: – current [3][4], in the Java program and this will return the value 500.

This is a vital stage of the project since this approach is applied mainly in the creation of databases to store all the data that is used. The following Examples 16 and 17 show the implementation of the gradient profile data using arrays.

An array of character strings

Implementing a one-dimensional array for Gradient profile and Speed limit title parameters. In this figure, item parameters [0] = Station name, parameters [1] = Station position (m), parameters [2] = Gradient and so forth, the last array value is parameters [5] which has the value End of Speed Limit (m). This array has no specified size and this means that it can expand to any size if we keep adding values to it.

An array of Objects (data)

The data displayed in this example has been adapted from Mike Smith’s program for the Advanced Railway Research Center, University of Sheffield, 27th October 1999.

A two dimensional array (data), in this case the value data [0][0] is null, since there is nothing within the double quotation marks (“ ”), the values data [0][1], data [0][2],  data [0][3],  data [0][4],and data[0][5], are all 0’s , the value data [1][0]= Camden Town and so on.   In the Train simulator program, the above two codes are linked together to produce a table l shown in

A data table produced using the one-dimensional and the two-dimensional arrays mapped together in a table format (See section 3.3.4 on Arrays and Tabling). The data displayed on this table has been adapted from Mike Smith’s program for the Advanced Railway Research Center, University of Sheffield, 27th October 1999.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please support the site
By clicking any of these buttons you help our site to get better
Social PopUP by Timersys