Advertisement
Guest User

Untitled

a guest
May 1st, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. private void generate(int[] dateOfBirth, int gender) {
  2. int[] wholePesel = new int[11];
  3. wholePesel[9] = gender;
  4. for(int i=0;i<6;i++) {
  5. wholePesel[i] = dateOfBirth[i];
  6. }
  7.  
  8. while(wholePesel[9] < 10) {
  9. wholePesel[8]++;
  10.  
  11. if(wholePesel[8] > 9) {
  12. wholePesel[7]++;
  13. wholePesel[8] = 0;
  14. }
  15.  
  16. if(wholePesel[7] > 9) {
  17. wholePesel[6]++;
  18. wholePesel[7] = 0;
  19. }
  20.  
  21. if(wholePesel[6] > 9) {
  22. wholePesel[9] += 2;
  23. wholePesel[8] = 0;
  24. wholePesel[7] = 0;
  25. wholePesel[6] = 0;
  26. }
  27.  
  28. for(int i=0;i<10;i++) {
  29. wholePesel[10] = i;
  30. boolean isPeselValid = checkIfPeselIsValid(wholePesel);
  31. if(isPeselValid == true) {
  32. long pesel = arrayToLong(wholePesel);
  33. peselList.add(pesel);
  34. }
  35. }
  36. }
  37. }
  38.  
  39.  
  40. private boolean checkIfPeselIsValid(int[] wholePesel) {
  41.  
  42. int checkSum = wholePesel[0]+wholePesel[1]*3+wholePesel[2]*7+wholePesel[3]*9
  43. +wholePesel[4]*1+wholePesel[5]*3+wholePesel[6]*7+wholePesel[7]*9+wholePesel[8]*1
  44. +wholePesel[9]*3+wholePesel[10];
  45.  
  46. if(checkSum%10==0) {
  47. return true;
  48. }
  49.  
  50. return false;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement