Solucio Profes

De wikiserver
Dreceres ràpides: navegació, cerca

ECMA6

class Persona {
                constructor(nombre, apellido, edad) {
                    this.nombre = nombre;
                    this.apellido = apellido;
                    this.edad = edad;
                }

                set cambiarNombre(n) {
                    this.nombre = n;
                }

                get obtenerNombre() {
                    return this.nombre;
                }

                set cambiarApellido(n) {
                    this.apellido = n;
                }

                get obtenerApellido() {
                    return this.apellido;
                }

                set cambiarEdad(n) {
                    this.edad = n;
                }

                get obtenerEdad() {
                    return this.edad;
                }

                mostrar() {
                    document.write("<br>");
                    document.write(" " + this.nombre);
                    document.write(" " + this.apellido);
                    document.write(" " + this.edad);
                }

            }


            class Profesor extends Persona {
                constructor(nombre, apellido, edad) {
                    super(nombre, apellido, edad);
                }

                mostrar() {
                    document.write("<br>");
                    super.mostrar();
                }

            }


            class PFijo extends Profesor {
                constructor(nombre, apellido, edad, id) {
                    super(nombre, apellido, edad);
                    this.id = id;
                }

                get obtenerId() {
                    return this.id;
                }

                set obtenerId(id) {
                    this.id = id;
                }

                mostrar() {

                    super.mostrar();
                    document.write(" " + this.id);

                }

            }


            class PInterino extends Profesor {
                constructor(nombre, apellido, edad, fecha) {
                    super(nombre, apellido, edad);
                    this.fecha = fecha;
                }

                get obtenerFecha() {
                    return this.fecha;
                }

                set obtenerId(fecha) {
                    this.fecha = fecha;
                }

                mostrar() {

                    super.mostrar();
                    document.write(" " + this.fecha);

                }

            }


            class ListaP {

                constructor() {
                    this.lista = [];
                }

                set insertarProfe(pers) {

                    this.lista.push(pers);
                }

                get obtenerProfe() {
                    return this.lista.pop();

                }

                mostrarProfes() {

                    for (var i = this.lista.length - 1; i >= 0; i--) {
                        var valor = this.lista.pop();
                     // if(valor instanceof PInterino)    //sólo imprime aquellos profes interinos
                        valor.mostrar();
                    }

                }

            }


            var person = new Persona("julio", "noguera", 12);
            var pr = new Profesor("sergio", "rodriguez", 16);
            var pr = new PInterino("sergio", "rodriguez", 34, new Date().getDate());
            var listaProfe = new ListaP();

            listaProfe.insertarProfe = person;
            listaProfe.insertarProfe = pr;
            listaProfe.insertarProfe = new PFijo("pepe", "ramirez", 12, 123);
            listaProfe.insertarProfe = new PInterino("juanra", "tamiz", 23, new Date().getDate());

//var perso=listaProfe.obtenerProfe();   //obtendria últim Profe

            listaProfe.mostrarProfes();



function Persona(nombre,apellido,edad){
	this.nombre=nombre;
	this.apellido=apellido;
	this.edad=edad;
}

Persona.prototype.getNombre=function(){
	return nombre;
}

Persona.prototype.setNombre=function(name){
	this.nombre= name;
}

Persona.prototype.getApellido=function(){
	return apellido;
}

Persona.prototype.setApellido=function(surname){
	this.apellido= surname;
}

Persona.prototype.getedad=function(){
	return edad;
}

Persona.prototype.setedad=function(age){
	this.edad= age;
}


Persona.prototype.mostrarP=function(){
	document.write(this.nombre);
	document.write(this.apellido);

}

function Profesor(nombre, apellido, edad){

Persona.call(this,nombre, apellido, edad);

}
//Hereda de Persona
Profesor.prototype=new Persona();
//Apunta al constructor de Profesor
Profesor.prototype.constructor=Profesor;


Profesor.prototype.getNombre=function(){
	return nombre;
}

Profesor.prototype.setNombre=function(name){
	this.nombre= name;
}

Profesor.prototype.getApellido=function(){
	return apellido;
}

Profesor.prototype.setApellido=function(surname){
	this.apellido= surname;
}

Profesor.prototype.getedad=function(){
	return edad;
}

Profesor.prototype.setedad=function(age){
	this.edad= age;
}

Profesor.prototype.mostrarP=function(){
	document.write(this.nombre);
	document.write(this.apellido);

}


function PFijo(nombre, apellido, edad,id){

Persona.call(this,nombre, apellido, edad);

this.id=id;
}

//Hereda de Persona
PFijo.prototype=new Persona();
// corrige el puntero del constructor porque apunta a Persona
PFijo.prototype.constructor=PFijo;


PFijo.prototype.getNombre=function(){
	return nombre;
}

PFijo.prototype.setNombre=function(name){
	this.nombre= name;
}

PFijo.prototype.getApellido=function(){
	return apellido;
}

PFijo.prototype.setApellido=function(surname){
	this.apellido= surname;
}

PFijo.prototype.getedad=function(){
	return edad;
}

PFijo.prototype.setedad=function(age){
	this.edad= age;
}
PFijo.prototype.getId=function(){
	return edad;
}

PFijo.prototype.setId=function(identificacion){
	this.id= identificacion;
}

PFijo.prototype.mostrarP=function(){
	document.write(this.nombre);
	document.write(this.apellido);

}

function PInterino(nombre, apellido, edad, fecha){

Persona.call(this,nombre, apellido, edad);

this.fecha=fecha;

}

//Hereda de Persona
PInterino.prototype=new Persona();
// corrige el puntero del constructor porque apunta a Persona
PInterino.prototype.constructor=PInterino;


PInterino.prototype.getNombre=function(){
	return nombre;
}

PInterino.prototype.setNombre=function(name){
	this.nombre= name;
}

PInterino.prototype.getApellido=function(){
	return apellido;
}

PInterino.prototype.setApellido=function(surname){
	this.apellido= surname;
}

PInterino.prototype.getedad=function(){
	return edad;
}

PInterino.prototype.setedad=function(age){
	this.edad= age;
}

PInterino.prototype.setFecha=function(data){
	this.fecha=data;
}

PInterino.prototype.getFecha=function(){
	return fecha;
}

PInterino.prototype.mostrarP=function(){
	var that=this;
	document.write(this.nombre);
	document.write(this.apellido);
	document.write(this.fecha);

}

function ListaP(){

var lista=[]

this.insertarProfe=function(Profesor){
return lista.push(Profesor);
}

this.obtenerProfe=function(){
	return lista.pop();
}

this.mostrarProfes=function(){
	for (var i = lista.length - 1; i >= 0; i--) {
		var valor= lista.pop();
		valor.mostrarP();
	};
		
	}
}


var person= new Persona("julio","noguera",12);
var pr=new Profesor("sergio", "rodriguez",16);
var listaProfe= new ListaP();

listaProfe.insertarProfe(person);
listaProfe.insertarProfe(pr);
listaProfe.insertarProfe(new PFijo("pepe","ramirez",12,20038338));
listaProfe.insertarProfe(new PInterino("juanra","tamiz",23,new Date().getDate()));

//var perso=listaProfe.obtenerProfe();   //obtendria últim Profe

listaProfe.mostrarProfes();