Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.65 KB | None | 0 0
  1. //CURSO JAVA POO. CONSTRUCCION DE OBJETOS. VIDEOS 34-35
  2. //UNICO FICHERO FUENTE
  3. package poo;
  4. import java.util.*;
  5.  
  6. public class Uso_Empleados {
  7.     public static void main(String[] args) {
  8.         Jefatura jefe_RRHH= new Jefatura("LUCIANO", 999999, 1996, 07, 23);
  9.         jefe_RRHH.estableceIncentivo(1);
  10.         jefe_RRHH.dameSueldo();
  11.        
  12.         Empleado misEmpleados[]= new Empleado[6];
  13.         misEmpleados[0]= new Empleado("Paco Gomez", 10, 1990, 12, 17);
  14.         misEmpleados[1]= new Empleado("Ana Lopez",50, 1995, 06, 02);
  15.         misEmpleados[2]= new Empleado("Maria Martin", 15, 2002, 03, 15);
  16.         misEmpleados[3]= new Empleado("asdf", 60, 2002, 03, 15);
  17.         misEmpleados[4]= jefe_RRHH;//POLIMORFISMO EN ACCION - PRINCIPIO EN ACCION
  18.         misEmpleados[5]= new Jefatura("MARIA", 1, 1999, 5, 26);
  19.        
  20.         Jefatura jefe_Finanzas= (Jefatura)misEmpleados[5];
  21.         jefe_Finanzas.estableceIncentivo(100000);
  22.        
  23.         Empleado director_comercial= new Jefatura("DIRECTOR", 5000, 2012, 02, 32);
  24.         Comparable ejemplo= new Empleado("ELI", 9500, 1996, 02, 13);
  25.        
  26.         if(director_comercial instanceof Empleado){
  27.             System.out.println("ES DE TIPO JEFATURA");
  28.         }
  29.         if(ejemplo instanceof Comparable){
  30.             System.out.println("IMPLEMENTA LA INTERFAZ COMPARABLE");
  31.         }
  32.        
  33.         System.out.println(jefe_Finanzas.tomar_decisiones("RENUNCIAR"));
  34.         System.out.println(jefe_RRHH.tomar_decisiones("SOY PUTO"));
  35.        
  36.         //REFUNDICION:
  37.         double pene= 5.6;
  38.         int pene1= (int)pene;
  39.        
  40.        
  41.         System.out.println(jefe_Finanzas.establece_bonus(500));
  42.        
  43.         //ORDENAMIENTO SORT
  44.         Arrays.sort(misEmpleados);
  45.        
  46.        
  47.         //OPCION 2:
  48.         for(Empleado e: misEmpleados){
  49.             System.out.println("NOMBRE: " +e.dameNombre()
  50.                     +"\nSUELDO: " +e.dameSueldo()
  51.                     +"\nFECHA ALTA: " +e.dameFechaContrato()
  52.                     +"ID: " +e.dameId()
  53.                     +"\n-----------------");
  54.         }
  55.        
  56.     }
  57. }
  58.  
  59. class Empleado implements Comparable, Trabajadores{
  60.     private String nombre;
  61.     private double sueldo;
  62.     private Date altaContrato;
  63.     private int id;
  64.    
  65.     public static int idnext=1;
  66.     public Empleado(String nom, double sue, int agno, int mes, int dia){//CONSTRUCTORES
  67.         nombre=nom;
  68.         sueldo=sue;
  69.        
  70.         GregorianCalendar calendario = new GregorianCalendar(agno, mes-1, dia);
  71.         altaContrato= calendario.getTime();
  72.        
  73.         id=idnext;
  74.         idnext++;
  75.  
  76.     }
  77.     public double establece_bonus(double gratificacion){
  78.         return Trabajadores.bonus_base+gratificacion;
  79.     }
  80.  
  81.     public Empleado(String nom){//SOBRE CARGA DE CONSTRUCTOR
  82.         this(nom, 99999, 2017, 01, 01);
  83.     }
  84.    
  85.     public String dameNombre(){//GETTER
  86.         return nombre;
  87.     }
  88.     public double dameSueldo(){//GETTER
  89.         return sueldo;
  90.     }
  91.     public Date dameFechaContrato(){//GETTER
  92.         return altaContrato;
  93.     }
  94.     public int dameId(){
  95.         return id;
  96.     }
  97.    
  98.     public void subeSueldo(double porcentaje){//SETTER
  99.         double aumento=sueldo*porcentaje/100;
  100.         sueldo+=aumento;
  101.     }
  102.    
  103.     //COMPARE TO
  104.     public int compareTo(Object miObjeto){
  105.         Empleado otroEmpleado=(Empleado)miObjeto;
  106.         if(this.sueldo<otroEmpleado.sueldo){
  107.             return -1;
  108.         }
  109.         if(this.sueldo>otroEmpleado.sueldo){
  110.             return 1;
  111.         }
  112.         return 0;
  113.     }
  114.    
  115.    
  116. }
  117.  
  118. class Jefatura extends Empleado implements Jefes{
  119.     private double incentivo;
  120.    
  121.    
  122.     public Jefatura(String nom, double sue, int agno, int mes, int dia){
  123.         super(nom, sue, agno, mes, dia);
  124.     }
  125.     public void estableceIncentivo(double b){
  126.         incentivo=b;
  127.     }
  128.    
  129.     public String tomar_decisiones(String decision){
  130.         return "UN MIEMBRO DE LA DIRECCION HA TOMADO LA DEICCION DE: "+decision;
  131.     }
  132.    
  133.     public double establece_bonus(double gratificacion){
  134.         double prima=2000;
  135.         return Trabajadores.bonus_base+gratificacion+prima;
  136.     }
  137.    
  138.     public double dameSueldo(){//GETTER
  139.         double sueldoJefe= super.dameSueldo();
  140.         return sueldoJefe + incentivo;
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement