martes, 15 de octubre de 2013

Implementacion ArrayList

import java.util.*;
class Profesor
   {
      private String nombre;
      private int pago;
    
      public void  altas(ArrayList <Profesor>  os2)
        {
            Profesor aux = new Profesor();
        
            System.out.println( "teclea el nombre  " );
            aux.nombre = Leer.dato();
            System.out.println( "teclea el pago  " );
            aux.pago = Leer.datoInt();
            os2.add(aux);  
        }
      public void  consultas(ArrayList <Profesor>  os2)
        {
            Profesor aux = new Profesor();
      String nom = "";
     char encon = ' ';
            System.out.println( "teclea el nombre a buscar " );
            nom = Leer.dato();
            for (int i =0; i< os2.size() ; ++ i)               
               {
                  aux = os2.get(i);  
         if (nom.equals(aux.nombre))
        {
                       System.out.println( aux.pago);
        encon = 's';
           break;
     }
               }
   if (encon != 's')
                System.out.println("no se encontro el empleado ");
                 
        }
      public void  bajas(ArrayList <Profesor>  os2)
        {
            Profesor aux = new Profesor();
     String nom = "";    
            char opcb = ' ';
     char opcnoe = ' ';
            System.out.println( "teclea el nombre a buscar " );
            nom = Leer.dato();
            for (int i =0; i< os2.size() ; ++ i)               
               {
                  aux = os2.get(i);  
        if (nom.equals(aux.nombre))
        {
        opcnoe = 's';
                       System.out.println( aux.pago);
                       System.out.println( "es el objeto a borrar " );
        opcb = Leer.datoChar();
        if (opcb == 's')
        {
                             os2.remove(i);
                             System.out.println( "el profesor es borrado " );
              }
        else
                             System.out.println( "el profesor no es borrado " );
           break;
     }
                }
   if (opcnoe == 's')
        System.out.println( "el profesor no existe" );
        } 
    }

Creación ArrayList

import java.util.*;
class Escuela
    {
      public static void main(String [] args)
        {             
          Profesor aux = new Profesor();
          int opcion = 0;
        char opc = 's';   
       ArrayList <Profesor> arrprofes = new ArrayList <Profesor>();
       while (opc == 's')
       {
    System.out.println("1.- altas ");
    System.out.println("2.- bajas ");
    System.out.println("4.- consultas ");
    System.out.println("5.- fin ");
    System.out.println("teclea la opcion deseada ? ");
    opcion = Leer.datoInt();
    switch(op)
     {
     case 1:
                        aux.altas(arrprofes);
      break;
     case 2:
                           aux.bajas(arrprofes);
      break;
     case 4:
                           aux.consultas(arrprofes);
      break;
     case 5:
           opc = 'n';
      break;
     default:
      break;
     }
    }  
        }
    }