Diferència entre revisions de la pàgina «Solucio Profes»

De wikiserver
Dreceres ràpides: navegació, cerca
 
(Hi ha una revisió intermèdia del mateix usuari que no es mostren)
Línia 3: Línia 3:
 
<source lang="java">
 
<source lang="java">
  
class Persona{
+
          class Persona {
    constructor(nombre,apellido,edad){
+
                constructor(nombre, apellido, edad) {
        this.nombre=nombre;
+
                    this.nombre = nombre;
        this.apellido=apellido;
+
                    this.apellido = apellido;
        this.edad=edad;
+
                    this.edad = edad;
    }
+
                }
  
    set cambiarNombre(n){
+
                set cambiarNombre(n) {
        this.nombre=n;
+
                    this.nombre = n;
    }
+
                }
  
    get obtenerNombre(){
+
                get obtenerNombre() {
        return this.nombre;
+
                    return this.nombre;
    }
+
                }
  
    set cambiarApellido(n){
+
                set cambiarApellido(n) {
        this.apellido=n;
+
                    this.apellido = n;
    }
+
                }
  
    get obtenerApellido(){
+
                get obtenerApellido() {
        return this.apellido;
+
                    return this.apellido;
    }
+
                }
  
    set cambiarEdad(n){
+
                set cambiarEdad(n) {
        this.edad=n;
+
                    this.edad = n;
    }
+
                }
  
    get obtenerEdad(){
+
                get obtenerEdad() {
        return this.edad;
+
                    return this.edad;
    }
+
                }
  
    mostrar(){
+
                mostrar() {
        document.write("<br>");
+
                    document.write("<br>");
        document.write(" "+this.nombre);
+
                    document.write(" " + this.nombre);
        document.write(" "+this.apellido);
+
                    document.write(" " + this.apellido);
        document.write(" "+this.edad);
+
                    document.write(" " + this.edad);
    }
+
                }
  
 +
            }
  
}
 
  
 +
            class Profesor extends Persona {
 +
                constructor(nombre, apellido, edad) {
 +
                    super(nombre, apellido, edad);
 +
                }
  
class Profesor extends Persona{
+
                mostrar() {
    constructor(nombre,apellido,edad){
+
                    document.write("<br>");
      super(nombre,apellido,edad);
+
                    super.mostrar();
    }
+
                }
  
 +
            }
  
    mostrar(){
 
        document.write("<br>");
 
        document.write(" "+super.mostrar());
 
    }
 
  
}
+
            class PFijo extends Profesor {
 +
                constructor(nombre, apellido, edad, id) {
 +
                    super(nombre, apellido, edad);
 +
                    this.id = id;
 +
                }
  
 +
                get obtenerId() {
 +
                    return this.id;
 +
                }
  
class PFijo extends Persona{
+
                set obtenerId(id) {
    constructor(nombre,apellido,edad, id){
+
                    this.id = id;
        super(nombre,apellido,edad);
+
                }
        this.id=id;
 
    }
 
  
    get obtenerId(){
+
                mostrar() {
        return this.id;
 
    }
 
  
    set obtenerId(id){
+
                    super.mostrar();
        this.id=id;
+
                    document.write(" " + this.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;
 +
                }
  
class PInterino extends Persona{
+
                set obtenerId(fecha) {
    constructor(nombre,apellido,edad, fecha){
+
                    this.fecha = fecha;
        super(nombre,apellido,edad);
+
                }
        this.fecha=fecha;
 
    }
 
  
    get obtenerFecha(){
+
                mostrar() {
        return this.fecha;
 
    }
 
  
    set obtenerId(fecha){
+
                    super.mostrar();
        this.fecha=fecha;
+
                    document.write(" " + this.fecha);
    }
 
  
    mostrar(){
+
                }
  
        super.mostrar();
+
            }
        document.write(" "+this.fecha);
 
  
    }
 
  
    }
+
            class ListaP {
  
 +
                constructor() {
 +
                    this.lista = [];
 +
                }
  
    class ListaP{
+
                set insertarProfe(pers) {
  
    constructor(){
+
                    this.lista.push(pers);
    this.lista=[];
+
                }
    }
 
  
    set insertarProfe(pers){
+
                get obtenerProfe() {
 +
                    return this.lista.pop();
  
        this.lista.push(pers);
+
                }
    }
 
  
    get obtenerProfe(){
+
                mostrarProfes() {
        return this.lista.pop();
 
  
    }
+
                    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();
 +
                    }
  
    mostrarProfes(){
+
                }
  
        for (var i = this.lista.length - 1; i >= 0; i--) {
+
             }
             var valor= this.lista.pop();
 
            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;
var person= new Persona("julio","noguera",12);
+
            listaProfe.insertarProfe = pr;
var pr=new Profesor("sergio", "rodriguez",16);
+
            listaProfe.insertarProfe = new PFijo("pepe", "ramirez", 12, 123);
var pr=new PInterino("sergio", "rodriguez",34,new Date().getDate());
+
            listaProfe.insertarProfe = new PInterino("juanra", "tamiz", 23, 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
 
//var perso=listaProfe.obtenerProfe();  //obtendria últim Profe
  
listaProfe.mostrarProfes();
+
            listaProfe.mostrarProfes();
  
  

Revisió de 20:27, 6 nov 2017

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();