domingo, 13 de marzo de 2011

PROGRAMA: PROYECTO-APLET

LÓGICA:

Clase Cadena.

package Logica;

public class Cadena
{
    private String frace;

    public Cadena()
    {
    }

    public Cadena(String frace)
    {
        this.frace = frace;
    }

    public String getFrace()
    {
        return frace;
    }

    public void setFrace(String frace)
    {
        this.frace = frace;
    }

    public int contadordeletras()
    {
    int contador=0,longitud=0;
    char letra;
    longitud=frace.length();
    for(int i=0;i<longitud;i++)
    {
        letra=frace.charAt(i);
        if((letra>='a')&&(letra<='z')||(letra>='A')&&(letra<='z'))
            if((letra!='a')&&(letra!='e')&&(letra!='i')&&(letra!='o')&&(letra!='u'))
                if((letra!='A')&&(letra!='E')&&(letra!='I')&&(letra!='O')&&(letra!='U'))
                    contador++;
    }
    return contador;
    }

}


PRESENTACIÓN:

Clase Nombre:

package Presentacion;

import Logica.Cadena;
import javax.swing.JOptionPane;

public class Nombre extends java.applet.Applet
{

    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
           
            ex.printStackTrace();
           }
        this.setSize(400,300);
    }
                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lblletrero = new javax.swing.JLabel();
        txtfrace = new javax.swing.JTextField();
        btncontador = new javax.swing.JButton();

        setFont(new java.awt.Font("Arial", 1, 48)); // NOI18N

        jLabel1.setForeground(new java.awt.Color(255, 51, 51));
        jLabel1.setText("Ejercicio con frace");

        lblletrero.setBackground(new java.awt.Color(51, 255, 255));
        lblletrero.setForeground(new java.awt.Color(153, 0, 51));
        lblletrero.setText("Digite frace");

        btncontador.setBackground(new java.awt.Color(51, 51, 255));
        btncontador.setForeground(new java.awt.Color(255, 0, 255));
        btncontador.setText("contar letra");
        btncontador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btncontadorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblletrero, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(133, 133, 133)
                .addComponent(txtfrace, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
            .addGroup(layout.createSequentialGroup()
                .addGap(128, 128, 128)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btncontador)
                    .addComponent(jLabel1))
                .addContainerGap(169, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(70, 70, 70)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblletrero)
                    .addComponent(txtfrace, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(72, 72, 72)
                .addComponent(btncontador)
                .addGap(67, 67, 67))
        );
    }                       

    private void btncontadorActionPerformed(java.awt.event.ActionEvent evt) {                                            
        
        Cadena obj1=new Cadena();
        obj1.setFrace(this.txtfrace.getText());
       JOptionPane.showMessageDialog(null,obj1.contadordeletras() );

    }                                                                
    private javax.swing.JButton btncontador;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lblletrero;
    private javax.swing.JTextField txtfrace;                   

}

PROGRAMA: CAPICUA

FarmSatoshi Enjoy Free Satoshi!
LÓGICA:

Clase Capicua.

package Logica;

public class Capicua
{
 private int num;


 public Capicua(int num) 
    {
        this.num = num;
    }

    public int getNum() {
        return num;
    }
    public void setNum(int num) 
    {
        this.num = num;
    }
  
 public int invertir()
 {
  int num2,num3,aux,aux2,pot,resul;
  aux=pot=resul=0;
  num2=num;
  do{
  num2=num2/10;
  aux++;
  }while(num2>10);
   aux2=num;
   num3=0;
   int k=aux;
  for(int i=0;i<=aux;i++)
  {
  pot=1;
  for(int j=0;j<k;j++)
   {
    pot*=10;
   }
   k=k-1;
   num3=aux2%10;
   aux2/=10;
   num3*=pot;
   resul+=num3;
   }

  return resul;
 }
}




PRESENTACIÓN:

Clase Formulario1.

package Presentacion;
import javax.swing.JOptionPane;
import Logica.Capicua;

public class Formulario1
{
public static void main(String arg[])
{
 Capicua obj=new Capicua(0);
 int num=0,numr=0;
 do{
 num=Integer.parseInt(JOptionPane.showInputDialog("ingrese un numero mayor a dos cifras: "));
 }while(num<10);
 if(num==101)
  {
  numr=101;
  }
 else
  {
  obj.setNum(num);
  numr=obj.invertir();
  }
 if(numr==num)
 {
  JOptionPane.showMessageDialog(null,"el numero "+num+" es capicua");
 }
 else
    JOptionPane.showMessageDialog(null,"el numero "+num+" no es capicua");
  
}
}




PROGRAMA: NOTAS

FarmSatoshi Enjoy Free Satoshi!
LÓGICA:

Clase Estudiante.

package Logica;



public class Estudiante
{
 private float nota1,nota2,nota3,porc1,porc2,porc3;

    public Estudiante(float nota1, float nota2, float nota3, float porc1, float porc2, float porc3)
    {
        this.nota1 = nota1;
        this.nota2 = nota2;
        this.nota3 = nota3;
        this.porc1 = porc1;
        this.porc2 = porc2;
        this.porc3 = porc3;
    }
   public Estudiante()
    {
     nota1=0;
     nota2=0;
     nota3=0;
     porc1=0;
     porc2=0;
     porc3=0;
    }
    public float getNota1()
    {
        return nota1;
    }

    public void setNota1(float nota1)
    {
        this.nota1 = nota1;
    }

    public float getNota2()
    {
        return nota2;
    }

    public void setNota2(float nota2)
    {
        this.nota2 = nota2;
    }

    public float getNota3()
    {
        return nota3;
    }

    public void setNota3(float nota3)
    {
        this.nota3 = nota3;
    }

    public float getPorc1()
    {
        return porc1;
    }

    public void setPorc1(float porc1)
    {
        this.porc1 = porc1;
    }

    public float getPorc2()
    {
        return porc2;
    }

    public void setPorc2(float porc2)
    {
        this.porc2 = porc2;
    }

    public float getPorc3()
    {
        return porc3;
    }

    public void setPorc3(float porc3)
    {
        this.porc3 = porc3;
    }

  public float calcular()
   {
    float aux,notat;
    aux=notat=0;
    if(nota1>10)
    {
      nota1=nota1/10; 
    }
    aux=(nota1*porc1)/100;
    notat+=aux;
    if(nota2>10)
    {
      nota2=nota2/10;
    }
    aux=(nota2*porc2)/100;
    notat+=aux;
    if(nota3>10)
    {
      nota3=nota3/10;
    }
    aux=(nota3*porc3)/100;
    notat+=aux;
    return notat;
   }



}



PRESENTACIÓN:

Clase Formulario1.

package Presentacion;
import Logica.Estudiante;
import javax.swing.JOptionPane;

public class Formulario1
{
 public static void main(String arg[])
  {
     int t,error;
     float nota,porc,port=0;
     

    t=Integer.parseInt(JOptionPane.showInputDialog("ingrese la cantidad de estudiantes: "));

     Estudiante obj[]=new Estudiante[t];
     int cod[]=new int[t];
     float notat[]=new float[t];
     String nombre[]=new String[t];
     for(int i=0;i<t;i++)
     {
       obj[i]=new Estudiante();
       nota=porc=error=0;
     nombre[i]=JOptionPane.showInputDialog("ingrese nombre del estudiante: ");
     cod[i]=Integer.parseInt(JOptionPane.showInputDialog("ingrese codigo: "));

     nota=Float.parseFloat(JOptionPane.showInputDialog("ingrese nota 1: "));
     obj[i].setNota1(nota);
      nota=Float.parseFloat(JOptionPane.showInputDialog("ingrese nota 2: "));
     obj[i].setNota2(nota);
     nota=Float.parseFloat(JOptionPane.showInputDialog("ingrese nota3: "));
     obj[i].setNota3(nota);
     do{
       if(error==1)
       {
       JOptionPane.showMessageDialog(null,"ERROR: la suma de los porsentajes no es es igual a 100% \n" +
               "porfavor ingrese los porsentajes nuavamente");
       }
       error=0;
     porc=Float.parseFloat(JOptionPane.showInputDialog("ingrese porcentage de la nota 1: "));
     obj[i].setPorc1(porc);
     porc=Float.parseFloat(JOptionPane.showInputDialog("ingrese porcentage de la nota 2: "));
     obj[i].setPorc2(porc);
    porc=Float.parseFloat(JOptionPane.showInputDialog("ingrese porcentage de la nota 3: "));
     obj[i].setPorc3(porc);
     error++;
     port=obj[i].getPorc1()+obj[i].getPorc2()+obj[i].getPorc3();
     }while(port!=100);
     
     
     
     

     notat[i]=obj[i].calcular();
     }
     for(int i=0;i<t;i++)
      {
        float def=0;
        if(notat[i]<0.475)
        {
         def=0;
        }
        else
            if((notat[i]>=0.475)&(notat[i]<0.875))
            {
             def=(float) 0.5;
            }
            else
                if((notat[i]>=0.875)&(notat[i]<1.475))
                {
                 def=1;
                }
                else
                    if((notat[i]>=1.475)&(notat[i]<1.875))
                     {
                      def=(float) 1.5;
                     }
                    else
                        if((notat[i]>=1.875)&(notat[i]<2.475))
                        {
                         def=2;
                        }
                        else
                            if((notat[i]>=2.475)&(notat[i]<2.875))
                            {
                            def=(float) 2.5;
                            }
                            else
                                if((notat[i]>=2.875)&(notat[i]<3.475))
                                {
                                def=3;
                                }
                                else
                                    if((notat[i]>=3.475)&(notat[i]<3.875))
                                        {
                                        def=(float) 3.5;
                                        }
                                   else
                                       if((notat[i]>=3.875)&(notat[i]<4.475))
                                    {
                                    def=4;
                                    }
                                    else
                                        if((notat[i]>=4.475)&(notat[i]<4.875))
                                    {
                                    def=(float) 4.5;
                                    }
                                    else
                                        def=5;

     JOptionPane.showMessageDialog(null, nombre[i]+"\n"+cod[i]+"\nacumulado"+notat[i]+
               "\ndefinitiva"+def);
      }
  }

}

sábado, 12 de marzo de 2011

PROGRAMA: NOMINA

FarmSatoshi Enjoy Free Satoshi!
LÓGICA:

Clase Nomina.

package Logica;
  
public class Nomina 
{
 private int ht,hed,hen,hedf,henf;float salario; 

 public Nomina(int ht, int hed, int hen, int hedf, int henf, float salario) 
  {
  this.ht = ht;
  this.hed = hed;
  this.hen = hen;
  this.hedf = hedf;
  this.henf = henf;
  this.salario = salario;
  }

    public int getHed() 
    {
        return hed;
    }

    public void setHed(int hed) 
    {
        this.hed = hed;
    }

    public int getHedf() 
    {
        return hedf;
    }

    public void setHedf(int hedf) 
    {
        this.hedf = hedf;
    }

    public int getHen() 
    {
        return hen;
    }

    public void setHen(int hen) 
    {
        this.hen = hen;
    }

    public int getHenf() 
    {
        return henf;
    }

    public void setHenf(int henf) 
    {
        this.henf = henf;
    }

    public int getHt() 
    {
        return ht;
    }

    public void setHt(int ht) 
    {
        this.ht = ht;
    }

    public float getSalario() 
    {
        return salario;
    }

    public void setSalario(float salario) 
    {
        this.salario = salario;
    }
public Nomina() 
  {
  ht=0;
  hed=0;
  hen=0;
  hedf=0;
  henf=0;
  salario=0;
  }
    
public float calcular()
{

 float aux,dias,salariot;
    dias=(salario/30)/8;
    
    aux=(float) (salario * 0.08);

salariot=salario-aux;
if(salario<(2*535600))
    {
     salariot=salario+63600;
    }
    if(hed>0)
    {
     salariot=(float) (salariot + (dias + (hed * (dias * 0.25))));
    }
    if(hen>0)
    {
     salariot=(float) (salariot + (dias + (hen *(dias * 0.75))));
    }
    if(hedf>0)
    {
     salariot=(float) (salariot + (dias + (hedf * dias )));
    }
    if(henf>0)
    {
     salariot=(float) (salariot + (dias + (henf * (dias * 1.5))));
    }

 return salariot;
}

}


PRESENTACIÓN:

Clase Formulario1.

package Presentacion;
import javax.swing.JOptionPane;
import Logica.Nomina;

public class Formulario1
{
public static void main(String arg[])
 {
  
  int t,hd,hn,hdf,hnf;
  float salario=0;
  t=hd=hn=hdf=hnf=0;
  
    t=Integer.parseInt(JOptionPane.showInputDialog("ingrese la cantidad de empleados: "));

   Nomina obj[]=new Nomina[t];
   float salariot[]=new float[t];
   int id[]=new int[t];
   String nombre[]=new String[t];

   for(int i=0;i<t;i++)
   {
    obj[i]=new Nomina();


   nombre[i]=(JOptionPane.showInputDialog("nombre del empleado: "));
   id[i]=Integer.parseInt(JOptionPane.showInputDialog("identificacion del " +
           "empleado: "));

   hd=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "diurnas: "));

   hn=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "nocturnas: "));
   hdf=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "diurnas festivas: "));
   hnf=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "nocturnas festivas: "));
   salario=Float.parseFloat(JOptionPane.showInputDialog("ingrese salario: "));
   
   obj[i].setHed(hd);
   obj[i].setHen(hn);
   obj[i].setHedf(hdf);
   obj[i].setHenf(hnf);
   obj[i].setSalario(salario);
   salariot[i]=obj[i].calcular();
   //JOptionPane.showMessageDialog(null,obj[i].calcular());
  
  
   }
   for(int i=0;i<t;i++)
   {
   JOptionPane.showMessageDialog(null,"nombre de empleado: "+nombre[i]+
           "\nidentificacion: "+id[i]+"\nsalario total: "+salariot[i]);
   }
 }
}


Clase Formulario2.

package Presentacion;
import javax.swing.JOptionPane;
import Logica.Nomina;

public class Formulario2 
{
 public static void main(String arg[])
 {
  int hd,hn,hdf,hnf,id;
  float salario=0,salariot=0;
  hd=hn=hdf=hnf=id=0;
  String nombre;
  Nomina obj=new Nomina();

 nombre=(JOptionPane.showInputDialog("nombre del empleado: "));
 id=Integer.parseInt(JOptionPane.showInputDialog("identificacion del " +
           "empleado: "));

   hd=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "diurnas: "));

   hn=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "nocturnas: "));
   hdf=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "diurnas festivas: "));
   hnf=Integer.parseInt(JOptionPane.showInputDialog("ingrese horas extras " +
           "nocturnas festivas: "));
   salario=Float.parseFloat(JOptionPane.showInputDialog("ingrese salario: "));

   obj.setHed(hd);
   obj.setHen(hn);
   obj.setHedf(hdf);
   obj.setHenf(hnf);
   obj.setSalario(salario);
   salariot=obj.calcular();

   JOptionPane.showMessageDialog(null,"nombre de empleado: "+nombre+
           "\nidentificacion: "+id+"\nsalario total: "+salariot);
 }

}

miércoles, 9 de marzo de 2011

PROGRAMA: PARQUEADERO

FarmSatoshi Enjoy Free Satoshi!



LÓGICA:

Clase Tiempo.




package Logica;

public class Tiempo

{
private int h,m,s,d;


 public Tiempo(int d,int h, int m, int s)
 {
  this.d = d;
  this.h = h;
  this.m = m;
  this.s = s;
  
}

 public int getD()
 {
  return d;
 }
 public void setD(int d)
 {
  this.d = d;
 }
 public int getH()
 {
  return h;
 }
 public void setH(int h) 
 {
  this.h = h;
 }
 public int getM() 
 {
  return m;
 }
 public void setM(int m) 
 {
  this.m = m;
 }
 public int getS() 
 {
  return s;
 }
 public void setS(int s) 
 {
  this.s = s;
 }

 public Tiempo()
    { d=0;
      h=0;
      m=0;
      s=0;
      
    }

 public Tiempo sumar(Tiempo t2)
 {
  Tiempo aux =new Tiempo();
  aux.s=s+t2.s;
  aux.m=m+t2.m;
  aux.h=h+t2.h;
  aux.d=d+t2.d;

  if(aux.s>59)
  {
   aux.s-=60;
   aux.m++;
  }

  if(aux.m>59)
  {
   aux.m-=60;
   aux.h++;
  }

  if(aux.h>25)
  {
   aux.h-=24;
   aux.d++;
  }

  return (aux);
 }

 public Tiempo restar(Tiempo t2)
 {
  Tiempo aux=new Tiempo(0,0,0,0);

  

  aux.s=s-t2.s;
  if(aux.s<0)
  {
   s+=60;
   t2.m++;
   aux.s=s-t2.s;
  }
  
  aux.m=m-t2.m;
  if(aux.m<0)
  {
   m+=60;
   t2.h++;
   aux.m=m-t2.m;
  }
  
  aux.h=h-t2.h;
   if(aux.h<0)
  {
   h+=24;
   t2.d++;
   aux.h=h-t2.h;
  }
  
  aux.d=d-t2.d;
  
  return (aux);
 }
}


PRESENTACIÓN:

Clase Formulario1.



package Presentacion;
import Logica.Tiempo;
public class Formulario1
{
 public static void main(String args[])
  {
  Tiempo t1,t2,tt;
  t1=new Tiempo(0,10,10,50);
  t2=new Tiempo(0,12,40,50);
  tt=new Tiempo(0,0,0,0);
  tt=t1.sumar(t2);
System.out.println("el tiempo total es: dias "+tt.getD()+" y tiempo "+tt.getH()+
          ":"+tt.getM()+":"+tt.getS());
 }
}

Clase Formulario2.




package Presentacion;

import Logica.Tiempo;

public class Formulario2
{
  public static void main(String args[])
  {
  Tiempo t1,t2,tt;
  t1=new Tiempo(0,10,10,50);
  t2=new Tiempo(0,12,40,51);
  tt=new Tiempo(0,0,0,0);
  tt=t1.restar(t2);
System.out.println("el tiempo total es: dias "+tt.getD()+" y tiempo "+tt.getH()+
          ":"+tt.getM()+":"+tt.getS());
 }
}

Clase Formulario3.



package presentacion;
import Logica.Tiempo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Formulario3 
{
public static void main(String arg[]) throws IOException

{
int d,h,m,s;
Tiempo t1,t2,tt;
t1 = new Tiempo();
t2=new Tiempo(1,2,3,7);

do{
System.out.println("  tiempo de entrada:\n digite dias ");
d=leer();
t1.setD(d);
}while(t1.getD()<0);

do{
System.out.println("digite horas ");
h= leer();
t1.setH(h);
}while((t1.getH()<0)||(t1.getH()>24));

do{
System.out.println("digite minutos ");
m= leer();
t1.setM(m);
}while((t1.getM()<0)||(t1.getM()>59));

do{
System.out.println("digite segundos ");
s= leer();
t1.setS(s);
}while((t1.getS()<0)||(t1.getS()>59));

do{
System.out.println("  tiempo de salida:\n digite dias ");
d=leer();
t2.setD(d);
}while(t2.getD()<0);

do{
System.out.println("digite horas ");
h= leer();
t2.setH(h);
}while((t2.getH()<0)||(t2.getH()>24));

do{
System.out.println("digite minutos ");
m= leer();
t2.setM(m);
}while((t2.getM()<0)||(t2.getM()>59));

do{
System.out.println("digite segundos ");
s= leer();
t2.setS(s);
}while((t2.getS()<0)||(t2.getS()>59));

tt=new Tiempo(0,0,0,0);
  tt=t1.sumar(t2);

System.out.println("el tiempo total es: dias "+tt.getD()+" y tiempo "+tt.getH()+
          ":"+tt.getM()+":"+tt.getS());

}
public static int leer() throws IOException
{
InputStreamReader entrada = new InputStreamReader (System.in) ;
BufferedReader lectura= new BufferedReader(entrada);
String cadena=lectura.readLine();
return(Integer.parseInt(cadena));
}
}


Clase Formulario4.




package presentacion;
import Logica.Tiempo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Formulario4
{
public static void main(String arg[]) throws IOException

{
int d,h,m,s;
Tiempo t1,t2,tt;
t1 = new Tiempo();
t2=new Tiempo(1,2,3,7);

do{
System.out.println("  tiempo de entrada:\n digite dias ");
d=leer();
t1.setD(d);
}while(t1.getD()<0);

do{
System.out.println("digite horas ");
h= leer();
t1.setH(h);
}while((t1.getH()<0)||(t1.getH()>24));

do{
System.out.println("digite minutos ");
m= leer();
t1.setM(m);
}while((t1.getM()<0)||(t1.getM()>59));

do{
System.out.println("digite segundos ");
s= leer();
t1.setS(s);
}while((t1.getS()<0)||(t1.getS()>59));

do{
System.out.println("  tiempo de salida:\n digite dias ");
d=leer();
t2.setD(d);
}while(t2.getD()<0);

do{
System.out.println("digite horas ");
h= leer();
t2.setH(h);
}while((t2.getH()<0)||(t2.getH()>24));

do{
System.out.println("digite minutos ");
m= leer();
t2.setM(m);
}while((t2.getM()<0)||(t2.getM()>59));

do{
System.out.println("digite segundos ");
s= leer();
t2.setS(s);
}while((t2.getS()<0)||(t2.getS()>59));

tt=new Tiempo(0,0,0,0);
  tt=t1.restar(t2);

System.out.println("el tiempo total es: dias "+tt.getD()+" y tiempo "+tt.getH()+
          ":"+tt.getM()+":"+tt.getS());

}
public static int leer() throws IOException
{
InputStreamReader entrada = new InputStreamReader (System.in) ;
BufferedReader lectura= new BufferedReader(entrada);
String cadena=lectura.readLine();
return(Integer.parseInt(cadena));
}
}