martes, 13 de noviembre de 2012

Altas Bajas y Concultas


Melissa Cambre Paulin y Erick Ballesteros


import java.util.*;
class principal
 {
                public static void main(String []args)
                  {
                      ArrayList <objs> arrayobjs = new ArrayList <objs> () ;
                      objs aux = new objs();
          char opcmenu = 's';
          int opcion = 0;
          while (opcmenu == 's')
             {
                                                    System.out.println("\n\t 1 Altas");
System.out.println("\n\t 2 Bajas");
 System.out.println("\n\t 3 Cambios");
 System.out.println("\n\t 4 Consultas");
 System.out.println("\n\t 5 Desplegar ordenados");
 System.out.println("\n\t 6 Salir");
 System.out.print("\n\t Teclea la opcion deseada ");
 opcion = Leer.datoInt();
 if (opcion < 1 || opcion > 6 )
                System.out.println("Opcion incorrecta teclea nuevamente");
                                                                else
                    if (opcion == 1)
                      {
                         objs aux2 = new objs();
                         aux2.altas();
                         arrayobjs.add(aux2); 
                          }   
                   else
                      if (opcion == 2)
                         aux.bajas(arrayobjs);
                      else
                         if (opcion == 3)
                            aux.cambios(arrayobjs);
                         else
                            if (opcion == 4)
                              aux.consultas(arrayobjs);
                            else
                               if (opcion == 5)
                                  aux.ordenar(arrayobjs);
                               else
                                  if (opcion == 6)
                                     opcmenu = 'n';                         
             } 
      }
  }




import java.util.*;
class objs
   {
       private int clave;
       private String titulo;
       private int costo;

       public void altas()
          {
             System.out.println("Teclea la clave ");
             clave = Leer.datoInt();
             System.out.println("Teclea el titulo ");
             titulo = Leer.dato();
             System.out.println("Teclea el costo ");
             costo = Leer.datoInt();
          }

       public void bajas(ArrayList <objs> aobjs)
          {
                int cla = 0, i = 0;
                char opcb = ' ', existe = 'n';
                                                               objs aux = new objs();
                System.out.println("Teclea la clave a borrar ");
                                                               cla = Leer.datoInt();
                for(i=0; i < aobjs.size(); i++)
                                                                 {
                                                                    aux = aobjs.get(i);
                                                        if (aux.clave == cla)
                                                                      {   
                         existe = 's';
                                                                                   System.out.println(aux.titulo);
                                                                                   System.out.println(aux.costo);
                                                                                   System.out.println("Es el objeto a borrar ");
                                                                                   opcb = Leer.datoChar();

                         if (opcb == 's')
                            {
                                                                                       aobjs.remove(i);
                             System.out.println("Se borra ");
                            }
                         else
                                                                                   System.out.println("No se borra ");
                         break;
                                                                      }
                   }
                if(existe == 'n')
                  System.out.println("No existe");  
          }

       public void cambios(ArrayList <objs> aobjs)
          {
            int cla = 0, ocam = 0;
            char opcb = ' ', existe = 'n', concam = 's';
                                               objs aux = new objs();
            String ctitulo = "";
            System.out.println("Teclea la clave a cambiar");
                                               cla = Leer.datoInt();
            for(int i = 0; i < aobjs.size(); i++)
                                                 {
                                                    aux = aobjs.get(i);
                                                    if (aux.clave == cla)
                                                                  {   
                      existe = 's';
                      while (concam == 's')
                         {
                                                               System.out.println("1  " + aux.titulo);
                                                                                      System.out.println("2  " + aux.costo);
                                                                                      System.out.println("Teclea el dato a cambiar ");
                                                                                      ocam = Leer.datoInt();
                            if (ocam == 1)
                              {
                                                            System.out.println("Teclea el titulo ");
                                                                aux.titulo = Leer.dato();                            
                              }
                            else
                              if (ocam == 2)
                                {
                                                              System.out.println("Teclea el costo ");
                                                                  aux.costo = Leer.datoInt();                                     
                                }
                                                       System.out.println("Desea cambiar otro dato ");
                                                           concam = Leer.datoChar();
                         }                              
                      aobjs.set(i,aux);  
                      break;
                                                                  }
              }
            if(existe == 'n')
               System.out.println("No existe");               
          }

       public void consultas(ArrayList <objs> aobjs)
          {
                int cla = 0, i = 0;
                char opcb = ' ', existe = 'n';
                                                               objs aux = new objs();
                System.out.println("Teclea la clave a consultar ");
                                                               cla = Leer.datoInt();
                for(i=0; i < aobjs.size(); i++)
                                                                 {
                                                                    aux = aobjs.get(i);
                                                        if (aux.clave == cla)
                                                                                 {   
                         System.out.println(aux.titulo);
                                                                                   System.out.println(aux.costo);
                         break;
                       }
                  }
                if(aobjs.size() == i)
                  System.out.println("No existe");
         }

       public void ordenar(ArrayList <objs> aobjs)
          {
            objs aux=new objs();
                                               objs aux2=new objs();
                                   System.out.println("\n\n");
                                               for(int i=0;i<aobjs.size();i++)
                                                  {
                                                    for(int o=0;o<aobjs.size()-1;o++)
                                                       {
                                                                      if(aobjs.get(o).clave > aobjs.get(o+1).clave)
                                                                        {
                                                                                                              aux=aobjs.get(o);
                                                                                                              aux2=aobjs.get(o+1);
                                                                                      aobjs.set(o,aux2);      
                                                                                      aobjs.set(o+1,aux);                                                                   
                                                                                   }
                                                                   }
                                                  }
                                               for(int i=0;i<aobjs.size();i++)                                              
                                                               System.out.println(aobjs.get(i).clave + "  " + aobjs.get(i).titulo + "  " + aobjs.get(i).costo);
                     }        

    }