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" );
        } 
    }

No hay comentarios:

Publicar un comentario