/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package konsolowa;

import java.util.Scanner;


public class Konsolowa {
    
    /*
    **********************************************
    nazwa funkcji: sprawdzPlec
    opis funkcji: pobiera ona pesel i zwraca plec z niego
    parametry: pesel - pesel który będziemy sprawdzac
    zwracany typ i opis: char - M, jeśli to mężczyzna, K, jeśli to jest kobieta
    autor: 31231231231
    ***********************************************
    */
    
    public static char sprawdzPlec(String pesel) {    
        int przedOstatniaLiczba = Character.getNumericValue(pesel.charAt(9));
        
        if(przedOstatniaLiczba % 2 == 0) {
            return 'K';
        }
        
        return 'M';
    }
    
     /*
    **********************************************
    nazwa funkcji: sprawdzPesel
    opis funkcji: pobiera ona pesel i sprawdza czy jest poprawny
    parametry: pesel - pesel który będziemy sprawdzac
    zwracany typ i opis: boolean, w zależności czy jest pesel poprawny
    autor: 31231231231
    ***********************************************
    */
    
    public static boolean sprawdzPesel(String pesel) {
        int[] wagi = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3};
        int suma = 0;
        int liczba = 0;
        
        
        for(int i=0; i<10; i++) {
            liczba = Character.getNumericValue(pesel.charAt(i));
            suma += liczba * wagi[i];
        }
        
        int m = suma % 10;
        int r = 0;
        
        if(m != 0) r = 10 - m;
        
        
        return r == Character.getNumericValue(pesel.charAt(10));
    }
    
    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        String pesel = "55030101193";
 
        
        System.out.println("Plec: " + sprawdzPlec(pesel));
        System.out.println("Czy pesel poprawy: " + sprawdzPesel(pesel));
    }
    
}
