I'm stuck with an assigment and hope somebody could help. The problem is to write a program to convert a 25 digits code to a 5 digit string represent their location in the array. This is what I have so far:
My question is how do I get the value of the string's location in the array? Any help is much appreciated. Thank you.
Code:
public class BarToZip
{
// codes for the array with every digit, starting with 0
private String digits[] = { "||:::", ":::||", "::|:|", "::||:", ":|::|",
":|:|:", ":||::", "|:::|", "|::|:", "|:|::" };
private String barCode;
//constructor
public BarToZip(String barCode)
{
this.barCode = barCode;
}
public String toZipCode()
{
String zipCode = "";
//starting position of the barcode section to look up
int beginString = 0;
//ending position of the barcode section to look up
int endString = 4;
//looping through the barcode
for (int i = 0; i < barCode.length(); i++)
{
//seperate the barcode into section of 5 symbols
String toLookUp = barCode.substring(beginString, endString);
//look up the symbol in the array(I might be wrong here)
for(String s : digits)
{
s = toLookUp;
}
//return the location of the barcode section(need completion)
//add to zip code string(need completion)
//move location of barcode section 5 positions to the right
beginString = beginString + 5;
endString = endString + 5;
}
return zipCode;
}
}
Comment