In: Computer Science
Hello, I need to come up with the java code for a program that looks at bank Account ID's and checks if it is in the frame work of Letter followed by 4 numbers, so for example "A001". I need it to be its own method, named checkAccountID() that passes the accountID as an argument to check if it is in that framework of one letter followed by 4 numbers. Any ideas?
Java Code:
class AccountCheck {
//Main method
public static void main(String args[]) {
//Creating object
AccountCheck accChk = new
AccountCheck();
System.out.println("\n
checkAccountID(\"A0123\"): " +
accChk.checkAccountID("A0123"));
System.out.println("\n
checkAccountID(\"80123\"): " +
accChk.checkAccountID("80123"));
System.out.println("\n
checkAccountID(\"A03\"): " + accChk.checkAccountID("A03"));
System.out.println("\n
checkAccountID(\"C2235\"): " +
accChk.checkAccountID("C2235"));
}
//Method that validates Account ID
public boolean checkAccountID(String ID) {
//Checking length
if(ID.length() != 5) {
return
false;
}
//Converting to char array
char[] c = ID.toCharArray();
//Checking first character
int val = (int)c[0];
if( (val >=65 && val
<= 90) || (val >=97 && val <= 122) ) {
//Checking for
numbers
for(int i=1;
i<=4; i++) {
val = (int)c[i];
//Checking ascii value
if(val < 48 || val > 57) {
return false;
}
}
return
true;
}
else {
return
false;
}
}
}
_____________________________________________________________________________________________________
Sample Run: