martes, 2 de septiembre de 2014

Practica 01



 ClassPerson

package classperson;
import java.util.Scanner;
import java.text.SimpleDateFormat;

/*
 *
 * @author Gabriel Aguiar E
 */
public class ClassPerson {
    public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
        //Instanciamos a las diferentes Clases del programa
        Alumno alumno = new Alumno ();
        Profesor profesor = new Profesor();
        Administrativo admi = new Administrativo();
        /*
            Ingresamos el tipo de formato de la fecha que nuestro
            programa utilizara. La función SimpleDateFormat pertenece a la
            librería import java.text.SimpleDateFormat;
        */
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        int tipo;
        System.out.println("Seleccionar el tipo de persona a registrar");
        System.out.println("1. Profesor");
        System.out.println("2. Alumno");
        System.out.println("3. Administrativo");
        System.out.println("Ingrese opción seleccionada: ");
        tipo = Integer.parseInt(in.nextLine());
        /*
            Convertimos la variable tipo a tipo entero, ya que al ingresarlo el
            programa éste lo reconoce como tipo String.
        */
       
        if (tipo == 1)
        {
            System.out.println("Ingresa tu número de Profesor: ");
            profesor.setId(Integer.parseInt(in.nextLine().toString()));
            System.out.println("Ingresa tu Nombre: ");
            profesor.setNombre(in.nextLine().toString());
            System.out.println("Ingresa el Sexo: ");
            profesor.setSexo(in.nextLine().toString());
            System.out.println("Ingrese la Fecha Nacimiento: ");
           
            try{
                profesor.setFechaNacimiento(sdf.parse(in.nextLine().toString()));
                //sdf.parse(in.nextLine().toString());
                //System.out.println(profesor.getFechaNacimiento());
             }
            catch(Exception e){
           
            }
            System.out.println("Ingrese la fecha de Ingreso: ");
            try{ profesor.setFechaIngreso(sdf.parse(in.nextLine()));}
            catch(Exception e){}
        } else if (tipo == 2)
        {
            System.out.println("Ingresa tu número de Alumno: ");
            alumno.setId(Integer.parseInt(in.nextLine().toString()));
            System.out.println("Ingresa tu Nombre: ");
            alumno.setNombre(in.nextLine().toString());
            System.out.println("Ingresa el Sexo: ");
            alumno.setSexo(in.nextLine().toString());
            System.out.println("Ingrese la Fecha Nacimiento: ");
            /*
            Utilizamos la validadcion try{} catch{} ya que el método Parse
            así lo solicita
            */
            try{ alumno.setFechaNacimiento(sdf.parse(in.nextLine()));}
            catch(Exception e){}
            System.out.println("Ingresa la Matricula: ");
            alumno.setMatricula(in.nextLine().toString());
            System.out.println("Ingresa el Campus: ");
            alumno.setCampus(Integer.parseInt(in.nextLine().toString()));
            System.out.println("Ingresa la Carrera: ");
            alumno.setCarrera(in.nextLine().toString());
        } else if( tipo == 3)
        {
            System.out.println("Ingresa tu número de Administrativo: ");
            admi.setId(Integer.parseInt(in.nextLine().toString()));
            System.out.println("Ingresa tu Nombre: ");
            admi.setNombre(in.nextLine().toString());
            System.out.println("Ingresa el Sexo: ");
            admi.setSexo(in.nextLine().toString());
            System.out.println("Ingrese la Fecha Nacimiento: ");
            try{ admi.setFechaNacimiento(sdf.parse(in.nextLine()));}
            catch(Exception e){}
            System.out.println("Ingresa la Fecha de Ingreso: ");
            try{ profesor.setFechaNacimiento(sdf.parse(in.nextLine()));}
            catch(Exception e){}
        }
       
        System.out.println(profesor.getId()+" "+profesor.getNombre()+ " " + profesor.getSexo()+" "+profesor.getFechaNacimiento()+ " "+ profesor.getFechaIngreso());
        System.out.println(alumno.getId()+" "+alumno.getNombre()+ " " + alumno.getSexo()+" "+alumno.getFechaNacimiento()+ " "+ alumno.getMatricula()+" "+alumno.getCampus()+" "+alumno.getCarrera());
        System.out.println(admi.getId()+" "+admi.getNombre()+ " " + admi.getSexo()+" "+admi.getFechaNacimiento()+ " "+ admi.getFechaIngreso());
    }
    }

 Clase Persona

package classperson;
import java.util.Date;
/**
 *
 * @author Aguiar
 */
public class Persona {
     private Integer _id;
     private String _nombre;
     private String _sexo;
     private Date _fechaNacimiento;
    
    /**
     * @return the _id
     */
    public Integer getId() {
        return _id;
    }

    /**
     * @param _id the _id to set
     */
    public void setId(Integer _id) {
        this._id = _id;
    }

    /**
     * @return the _nombre
     */
    public String getNombre() {
        return _nombre;
    }

    /**
     * @param _nombre the _nombre to set
     */
    public void setNombre(String _nombre) {
        this._nombre = _nombre;
    }

    /**
     * @return the _sexo
     */
    public String getSexo() {
        return _sexo;
    }

    /**
     * @param _sexo the _sexo to set
     */
    public void setSexo(String _sexo) {
        this._sexo = _sexo;
    }

    /**
     * @return the _fechaNacimiento
     */
    public Date getFechaNacimiento() {
        return _fechaNacimiento;
    }

    /**
     * @param _fechaNacimiento the _fechaNacimiento to set
     */
    public void setFechaNacimiento(Date _fechaNacimiento) {
        this._fechaNacimiento = _fechaNacimiento;
    }
   
}


Clase Profesor

package classperson;
import java.util.Date;
/**
 *
 * @author Aguiar
 */
public class Profesor extends Persona {
   private Date _fechaIngreso;

    /**
     * @return the _fechaIngreso
     */
    public Date getFechaIngreso() {
        return _fechaIngreso;
    }

    /**
     * @param _fechaIngreso the _fechaIngreso to set
     */
    public void setFechaIngreso(Date _fechaIngreso) {
        this._fechaIngreso = _fechaIngreso;
    }
}

Clase Administrativo

package classperson;
import java.util.Date;
/**
 *
 * @author Aguiar
 */
public class Administrativo extends Persona {
    private Date _fechaIngreso;

    /**
     * @return the _fechaIngreso
     */
    public Date getFechaIngreso() {
        return _fechaIngreso;
    }

    /**
     * @param _fechaIngreso the _fechaIngreso to set
     */
    public void setFechaIngreso(Date _fechaIngreso) {
        this._fechaIngreso = _fechaIngreso;
    }
}

Clase Alumno

package classperson;

/**
 *
 * @author Aguiar
 */
public class Alumno extends Persona{
    private String _matricula;
    private String _carrera;
    private Integer _campus;

    /**
     * @return the _matricula
     */
    public String getMatricula() {
        return _matricula;
    }

    /**
     * @param _matricula the _matricula to set
     */
    public void setMatricula(String _matricula) {
        this._matricula = _matricula;
    }

    /**
     * @return the _carrera
     */
    public String getCarrera() {
        return _carrera;
    }

    /**
     * @param _carrera the _carrera to set
     */
    public void setCarrera(String _carrera) {
        this._carrera = _carrera;
    }

    /**
     * @return the _campus
     */
    public Integer getCampus() {
        return _campus;
    }

    /**
     * @param _campus the _campus to set
     */
    public void setCampus(Integer _campus) {
        this._campus = _campus;
    }
}