/*
* @author BKChepkwony
* Created on 24 Aug 2011
*/
package com.jjpeople.arrays;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
/**
* Class demonstrating usage of arrays
*
* @author BKChepkwony
* Created on 24 Aug 2011
*/
/**
* @author BKChepkwony
* Created on 24 Aug 2011
*/
public class ArrayExample {
// Getting logger used for logging statements.
public Logger logger =
Logger.getLogger( ArrayExample.class );
private static final String END_OF_LINE_CHARACTER =
System.getProperty( "line.separator" );
private static final String SECTION_SEPERATOR =
"=========================================" +
"=======================================";
/**
* Prints a line with the correct end of line character
*
* @example The example the message came from
* @param message The message to print
*
*/
private void print( String example, String message ) {
print( example + " : " + message );
}
/**
* Prints a line with the correct end of line character
*
* @param message The message to print
*/
private void print( String message ) {
System.out.println( message + END_OF_LINE_CHARACTER );
}
/**
* Demonstrates initializing and populating a multi-dimensional array
* in one statement
*/
private void personalDetails() {
logger.debug( "personalDetails()" );
String[][][] personArray =
{
{ "John", " Muray", "1-10-1982" },
{ "Peter", " Kamau", "2-5-1987" },
{ "Mary", " Wambui", "8-5-1988" },
{ "Bethu", " Kips", "8-8-1987" },
{ "Cetera", " Omosh", "2-5-1987" }
};
String message = "Names:" +
personArray[0][0] [0]+personArray[0][1] [0] +"DOB: " +personArray[0][1] [1];
print( "personalDetails()", message );
message = "Names:" +
personArray[1][0] [0] + personArray[1][1] [0] +"DOB: " + personArray[1][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[2][0] [0] + personArray[2][1] [0] +"DOB: " +personArray[2][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[3][0] [0] + personArray[3][1] [0] +"DOB: " +personArray[3][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[4][0] [0] + personArray[4][1] [0] +"DOB: " +personArray[4][1] [1];
print( "printPersonalD()", message );
}
/**
* shows the contents of the multi dimensional array.
* Use the printPersonalD()
*/
private void printPersonalD() {
logger.debug( "printPersonalD()" );
print( SECTION_SEPERATOR );
personalDetails();
print( SECTION_SEPERATOR );
}
/**
* Constructor
*/
public ArrayExample() {
super();
}
/**
* This is the starting execution point of the program.
*
* @param args the args are parameters passed into this java program from
* the command line. In this example no parameters are being passed into
* this programme.
*/
public static void main( String[] args ) {
// Configure the logger to print to the screen
BasicConfigurator.configure();
ArrayExample myArrayExample = new ArrayExample();
myArrayExample.printPersonalD();
}
}
/*
* @author BKChepkwony
* Created on 24 Aug 2011
*/
package com.jjpeople.arrays;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
/**
* Class demonstrating usage of arrays
*
* @author BKChepkwony
* Created on 24 Aug 2011
*/
/**
* @author BKChepkwony
* Created on 24 Aug 2011
*/
public class ArrayExample {
// Getting logger used for logging statements.
public Logger logger =
Logger.getLogger( ArrayExample.class );
private static final String END_OF_LINE_CHARACTER =
System.getProperty( "line.separator" );
private static final String SECTION_SEPERATOR =
"=========================================" +
"=======================================";
/**
* Prints a line with the correct end of line character
*
* @example The example the message came from
* @param message The message to print
*
*/
private void print( String example, String message ) {
print( example + " : " + message );
}
/**
* Prints a line with the correct end of line character
*
* @param message The message to print
*/
private void print( String message ) {
System.out.println( message + END_OF_LINE_CHARACTER );
}
/**
* Demonstrates initializing and populating a multi-dimensional array
* in one statement
*/
private void personalDetails() {
logger.debug( "personalDetails()" );
String[][][] personArray =
{
{ "John", " Muray", "1-10-1982" },
{ "Peter", " Kamau", "2-5-1987" },
{ "Mary", " Wambui", "8-5-1988" },
{ "Bethu", " Kips", "8-8-1987" },
{ "Cetera", " Omosh", "2-5-1987" }
};
String message = "Names:" +
personArray[0][0] [0]+personArray[0][1] [0] +"DOB: " +personArray[0][1] [1];
print( "personalDetails()", message );
message = "Names:" +
personArray[1][0] [0] + personArray[1][1] [0] +"DOB: " + personArray[1][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[2][0] [0] + personArray[2][1] [0] +"DOB: " +personArray[2][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[3][0] [0] + personArray[3][1] [0] +"DOB: " +personArray[3][1] [1];
print( "printPersonalD()", message );
message = "Names:" +
personArray[4][0] [0] + personArray[4][1] [0] +"DOB: " +personArray[4][1] [1];
print( "printPersonalD()", message );
}
/**
* shows the contents of the multi dimensional array.
* Use the printPersonalD()
*/
private void printPersonalD() {
logger.debug( "printPersonalD()" );
print( SECTION_SEPERATOR );
personalDetails();
print( SECTION_SEPERATOR );
}
/**
* Constructor
*/
public ArrayExample() {
super();
}
/**
* This is the starting execution point of the program.
*
* @param args the args are parameters passed into this java program from
* the command line. In this example no parameters are being passed into
* this programme.
*/
public static void main( String[] args ) {
// Configure the logger to print to the screen
BasicConfigurator.configure();
ArrayExample myArrayExample = new ArrayExample();
myArrayExample.printPersonalD();
}
}