Advertisement
CrazyDave23

Ejercicio 6 - POO - Ejecutable

Jul 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1.  
  2. package ejercicio_6_poo;
  3.  
  4. /**
  5.  *
  6.  * @author david
  7.  */
  8. import java.util.Arrays;
  9. import java.util.List;
  10. import java.util.Scanner;
  11.  
  12. public class Ejecutable {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.         Scanner leer = new Scanner(System.in);
  19.         String a[] = {"asd", "dfg"};
  20.         List almacen = Arrays.asList(a);
  21.         int no_empleados;
  22.         String nombre;
  23.         int eleccion2 = 0;
  24.         System.out.println("Ingrese la cantidad de empleados que desea registrar");
  25.         no_empleados = leer.nextInt();
  26.  
  27.         Empleado listaEmpleados[] = new Empleado[no_empleados];
  28.        
  29.         for (int i=0; i<listaEmpleados.length; i++){
  30.            
  31.             System.out.println("¿Rango principal?\n1. Directivo \t 2. Operario");
  32.             int eleccion;
  33.             eleccion = leer.nextInt();
  34.  
  35.             if (eleccion < 1 || eleccion > 2){
  36.                 System.err.println("Ingrese un valor válido, apagando programa.");
  37.                 return;
  38.             }
  39.            
  40.             switch (eleccion){
  41.                 case 1:
  42.                     System.out.println("Ingrese el nombre del empleado");
  43.                     nombre = leer.next();
  44.                     listaEmpleados[i] = new Directivo(nombre);
  45.                     List lista = Arrays.asList(listaEmpleados);
  46.                     almacen = lista;
  47.                     break;
  48.                 case 2:
  49.                     System.out.println("Ingrese el nombre del empleado");
  50.                     nombre = leer.next();
  51.  
  52.                     listaEmpleados[i] = new Operario(nombre);
  53.                     lista = Arrays.asList(listaEmpleados);
  54.                     almacen = lista;
  55.                     System.out.println("Rango secundario: \n1.Oficial \t2.Tecnico");
  56.                     eleccion2 = leer.nextInt();
  57.                    
  58.                     if (eleccion2 < 1 || eleccion2 >2 ){
  59.                         System.err.println("Ingrese un valor válido, apagando programa.");
  60.                         return;
  61.                     }
  62.                    
  63.                     switch(eleccion2){
  64.                         case 1:
  65.                             listaEmpleados[i] = new Oficial(nombre);
  66.                             break;
  67.                         case 2:
  68.                             listaEmpleados[i] = new Tecnico(nombre);
  69.                             break;
  70.                     }
  71.                     break;
  72.                    
  73.  
  74.             }
  75.            
  76.  
  77.  
  78.         }
  79.            System.out.println(almacen.toString());
  80.     }
  81.    
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement