/**
*
* @author anmaston
*/
public class NewMain {
/*HERE I SET UP THE NAMES OF REGIONAL "SERVICE CENTRES"*/
public static final String SWNAME = "South West England";
public static final String SENAME = "South East England";
/*HERE I SET UP THE ARRAYS OF POSTCODE PREFIXES FOR WHICH THE
* PARTICULAR SERVICE CENTRE WILL COVER
*/
public static final String[] SW = {"SA", "LD", "HR", "WR", "CF", "NP", "GL",
"BS", "BA", "SN", "SP", "BH", "TA", "DT",
"EX", "PL", "TQ", "TR"};
public static final String[] SE = {"CV", "NN", "MK", "SG", "CB", "IP", "CO",
"OX", "HP", "CM", "RG", "ME", "GU", "RH",
"CT", "TN", "BN", "SO", "LU", "AL", "SS",
"SL", "PO", "WD", "EN", "HA", "NW", "N", "E",
"IG", "EC", "WC", "SW", "SE", "SM", "UB", "TW",
"KT", "CR", "BR", "DA", "RM"};
public static void main(String[] args) {
/*HERE I CREATE SERVICE CENTRES AND ASSIGN THEIR APPROPRIATE
* CONSTANT VALUES, I AM AWARE THIS ISNT ELEGANT, COULD I DEFINE
* CONSTANT OBJECTS? WHEN I TRIED I WASN'T ABLE TO ACCESS THE get/set
* METHODS (Unsuprisingly, when they were declared as static)
*/
ServiceCentre SWEST = new ServiceCentre();
SWEST.setName(SWNAME);
SWEST.setPostcodePrefixes(SW);
ServiceCentre SEAST = new ServiceCentre();
SEAST.setName(SENAME);
SEAST.setPostcodePrefixes(SE);
/*INITIALISE BOOLEAN "found" FOR CONDITIONAL STATEMENT*
* AND ALSO "i" FOR LOOP CONTROL
*/
Boolean found = false;
int i = 0;
String s = "BS482BH"; // THE POSTCODE STRING, FOR WHICH I NEED TO FIND
// THE APPROPRIATE SERVICE CENTRE (SWEST)
String[] strings = s.split("[0-9]"); //I SPLIT THE POSTCODE BEFORE THE FIRST
//NUMERIC VALUE, GIVING ME A STRING ARRAY
String string = strings[0]; //I READ ELEMENT 0 INTO STRING (THIS IS THE ONLY BIT I NEED)
System.out.println(string); //OUTPUT AS "BS", ALL WELL AND GOOD.
/*MY CONDITIONAL W/ NESTED ITERATION AND CONDITIONAL*/
/*AS FAR AS I CAN SEE MY SYNTAX IS ALL CORRECT, NOTHING FOR NETBEANS TO*
* MOAN ABOUT ANYWAY, AND I THINK THE LOGIC IS GOOD, BUT I DONT UNDERSTAND
* WHY IT WILL NOT WORK, PSEUDOCODE ALONGSIDE
*/
if (found != true) { //if the items not found then grab the list of prefixes for the south east
String[] prefixes = SEAST.getPostcodePrefixes();
while (prefixes[i] != null) { //then loop through all of the prefixes until the whole of prefixes[] is looped or
if (prefixes[i].equals(string)) { //if a prefix in the array is equal to the string, do something and set found to true.
System.out.println("found in southeast");
found = true;
}
i++; //increment the loop control for next iteration,
}
} else if (found != true) { //if not already found then:
i = 0; //set loop control back to 0
String[] prefixes = SWEST.getPostcodePrefixes(); //read the next set of prefixes in
while (prefixes[i] != null) { //do the same etc etc.
if (string.equals(prefixes[i])) {
System.out.println("found in southwest");
found = true;
}
i++;
}
}
}
}