Created
September 29, 2015 04:20
-
-
Save jononon/a9452232c2ef081553a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class dogtagexample{ | |
/** | |
* Checks that a dog tag is valid | |
* @param dogTag the dog tag to be checked | |
* @return true if the dog tag is a valid dog tag | |
*/ | |
public static boolean checkDogTag (String dogTag) { | |
if(dogTag.length()!=4) | |
throw new IndexOutOfBoundsException(); | |
int sumOfElements = 0; | |
for(int i = 0; i <= 2 ; i++) | |
sumOfElements+=Integer.parseInt(dogTag.substring(i,i+1),10); | |
char dogID = (char) (70+sumOfElements%10); | |
if(dogTag.equals(dogTag.substring(0,3)+dogID)) | |
return(true); | |
else | |
return(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment