Skip to content

Instantly share code, notes, and snippets.

@xlbruce
Last active February 18, 2016 17:05
Show Gist options
  • Save xlbruce/a5ef576b61c0174c321f to your computer and use it in GitHub Desktop.
Save xlbruce/a5ef576b61c0174c321f to your computer and use it in GitHub Desktop.
Faz a validação do TIA (Terminal Informativo do Aluno) do Mackenzie
package com.validator;
/**
* Faz a validação do TIA (Terminal Informativo do Aluno) do Mackenzie
* @author gilson
*/
public class TIAValidator {
private static final byte[] nums = {8, 7, 6, 5, 4, 3, 2};
private TIAValidator() {}
public static boolean validate(int tia) {
int lastDigit = tia % 10;
tia /= 10;
int remainder;
int sum = 0;
int i = 6; //Iterate from right to left
while (tia > 0) {
remainder = tia % 10;
sum += (remainder * nums[i--]);
tia /= 10;
}
remainder = sum % 11;
int calculatedDigit = (remainder <= 1) ? remainder : (11 - remainder);
return calculatedDigit == lastDigit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment