package com.ahuntsic.tp2;

/**
 * Personne.java
 * contient le nom, le prénom, la date de naissance et le sexe
 * Date: 07/10/2005
 * Pour: Mr. Mohammed Salah Bendelloul
 * Projet: Travail pratique #2
 *
 * @author Hassen Ben Tanfous
 */

//imports
import com.ahuntsic.outils.MaDate;
import java.io.*;

public class Personne implements Serializable {

    /** sexe masculin */
    public static final int MASCULIN = 1;

    /** sexe féminin */
    public static final int FEMININ = 2;

    //critères de validation

    /** critères de validation pour le nom */
    public static final int NOM_TAILLE = 20;

    /** critères de validation pour le prénom */
    public static final int PRENOM_TAILLE = 20;

    private String nom,
            prenom;

    private int sexe;

    private MaDate dateNaissance;

    public Personne(String nom, String prenom, int sexe, MaDate naissance) {
        valider(nom, prenom);

        this.sexe = sexe;
        dateNaissance = naissance;
    }

    /**
     * valide les attributs d'après les critères établis
     * @param nom String
     * @param prenom String
     */
    private void valider(String nom, String prenom) {
        if (nom.length() > NOM_TAILLE) {
            nom = nom.substring(0, NOM_TAILLE);
        }
        if (prenom.length() > PRENOM_TAILLE) {
            prenom = prenom.substring(0, PRENOM_TAILLE);
        }
        this.nom = nom;
        this.prenom = prenom;
    }

    public String getNom() {
        return nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public int getSexe() {
        return sexe;
    }

    public MaDate getDateNaissance() {
        return dateNaissance;
    }
} //Fin de la classe Personne
