Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void generate(int[] dateOfBirth, int gender) {
- int[] wholePesel = new int[11];
- wholePesel[9] = gender;
- for(int i=0;i<6;i++) {
- wholePesel[i] = dateOfBirth[i];
- }
- while(wholePesel[9] < 10) {
- wholePesel[8]++;
- if(wholePesel[8] > 9) {
- wholePesel[7]++;
- wholePesel[8] = 0;
- }
- if(wholePesel[7] > 9) {
- wholePesel[6]++;
- wholePesel[7] = 0;
- }
- if(wholePesel[6] > 9) {
- wholePesel[9] += 2;
- wholePesel[8] = 0;
- wholePesel[7] = 0;
- wholePesel[6] = 0;
- }
- for(int i=0;i<10;i++) {
- wholePesel[10] = i;
- boolean isPeselValid = checkIfPeselIsValid(wholePesel);
- if(isPeselValid == true) {
- long pesel = arrayToLong(wholePesel);
- peselList.add(pesel);
- }
- }
- }
- }
- private boolean checkIfPeselIsValid(int[] wholePesel) {
- int checkSum = wholePesel[0]+wholePesel[1]*3+wholePesel[2]*7+wholePesel[3]*9
- +wholePesel[4]*1+wholePesel[5]*3+wholePesel[6]*7+wholePesel[7]*9+wholePesel[8]*1
- +wholePesel[9]*3+wholePesel[10];
- if(checkSum%10==0) {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement