Zródło pesel

Program sprawdza poprawność wpisanego numeru Pesel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
////////////////////////////////////////////////////////////////
// Program sprawdza poprawnosc wpisanego numeru Pesel
////////////////////////////////////////////////////////////////
 
import java.io.*;
 
class Pesel {
    private String NumerPesel;
    private int PomnozonyPesel;
    private int[] waga = { 1, 3, 7, 9, 1, 3, 7, 9, 1, 3 };
 
    // -----------------------------------------------------------
    private void Mnozenie() {
        for (int i = 0; i < waga.length; i++)
            PomnozonyPesel += (waga[i] * Integer.parseInt(NumerPesel.substring(i, i + 1))) % 10;
    }
 
    // -----------------------------------------------------------
    public Pesel(String CiagCyfr) {
        NumerPesel = CiagCyfr;
    }
 
    // -----------------------------------------------------------
    public void Wyswietl() {
        System.out.print("PESEL: " + NumerPesel);
    }
 
    // -----------------------------------------------------------
    public void SprawdzPoprawnosc() {
        Mnozenie();
        int LiczbaKontrolnaOrg = Integer.parseInt(NumerPesel.substring(10, 11));
        int LiczbaKontrolnaNew, Peselek;
        Peselek = PomnozonyPesel % 10;
        if (Peselek == 0)
            LiczbaKontrolnaNew = 0;
        else
            LiczbaKontrolnaNew = 10 - Peselek;
        if (LiczbaKontrolnaOrg == LiczbaKontrolnaNew)
            System.out.println("Ten numer pesel jest poprawny: " + NumerPesel);
        else
            System.out.println("Ten numer nie jest poprawny: " + NumerPesel);
    }
}
 
// //////////////////////////////////////////////////////////////
 
class Uruchom {
    // -----------------------------------------------------------
    public static void main(String[] args) throws IOException {
        Pesel psl;
 
        System.out.println("Wpisz pesel, poprawna ilosc to 11 cyfr");
        BufferedReader stdin = new BufferedReader(new InputStreamReader(
                System.in), 1);
        String str = stdin.readLine();
        int dlugosc = str.length();
        if (dlugosc != 11)
            System.out.println("Niepoprawna ilosc znakow=" + dlugosc
                    + ", Poprawna ilosc znakow=11");
        else {
            psl = new Pesel(str);
            psl.SprawdzPoprawnosc();
        }
    }
}