domingo, 30 de septiembre de 2012

Letra Vocal Consonante


/* Letra Vocal Consonante con Switch
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS           *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ            *
                                      *  ErNeStO rOsAlEs CaRlOs                                          *
                                      *  ernestorosales@live.com                                              *
                                      *********************************************

   Problema 7.- Elaborar un programa que lea una letra y determine si es vocal, o
   constante.
*/

import java.io.*;

class Siete_LetraVocalConstante

 {

  public static void main (String args[]) throws IOException
 
   {
 
    BufferedReader LVC=new BufferedReader (new InputStreamReader (System.in));
   
   
    System.out.println("Ingresa una letra en minuscula ");
   
String CV1=LVC.readLine();
char ConstanteVocal=CV1.charAt(0);

switch(ConstanteVocal)

{
case 'a':

System.out.println("Vocal");

break;

case 'b':

System.out.println("Constante");

break;

case 'c':

System.out.println("Constante");

break;

case 'd':

System.out.println("Constante");

break;

case 'e':

System.out.println("Vocal");

break;

case 'f':

System.out.println("Constante");

break;

case 'g':

System.out.println("Constante");

break;

case 'h':

System.out.println("Constante");

break;

case 'i':

System.out.println("Vocal");

break;

case 'j':

System.out.println("Constante");

break;

case 'k':

System.out.println("Constante");

break;

case 'l':

System.out.println("Constante");

break;

case 'm':

System.out.println("Constante");

break;

case 'n':

System.out.println("Constante");

break;

    case 'o':

System.out.println("Vocal");

break;

case 'p':

System.out.println("Constante");

break;

case 'q':

System.out.println("Constante");

break;

case 'r':

System.out.println("Constante");

break;

case 's':

System.out.println("Constante");

break;

case 't':

System.out.println("Constante");

break;

case 'u':

System.out.println("Vocal");

break;

case 'v':

System.out.println("Constante");

break;

case 'w':

System.out.println("Constante");

break;

case 'x':

System.out.println("Constante");

break;

   case 'y':

System.out.println("Constante");

break;

case 'z':

System.out.println("Constante");

break;

default:

System.out.println("Ingresaste dato incorrecto");

break;

}


}

   }
     

Área Triangulo, Rectángulo, Circulo, Cuadrado con Switch


/* Área Triangulo, Rectángulo, Circulo, Cuadrado con Switch
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS           *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ            *
                                      *  ErNeStO rOsAlEs CaRlOs                                          *
                                      *  ernestorosales@live.com                                              *
                                      *********************************************
*/

import java.io.*;

class SwitchAreaTCRC

{
       
        public static void main (String args []) throws IOException
               
        {
               
                BufferedReader Option=new BufferedReader (new InputStreamReader (System.in));
               
               
                System.out.println("1.- Area del triangulo: ");
               
                System.out.println("2.- Area del rectangulo: ");
               
                System.out.println("3.- Area del circulo: ");
               
                System.out.println("4.- Area del cuadrado: ");
               
               
               
                System.out.println("Escribe el numero de la opcion deseada: ");
               
                  String Opcion1=Option.readLine();
                 
                  int O1=Integer.parseInt(Opcion1);
                           
       
                   switch(O1)
                       
                   {
                   
                     case 1:  
                       
                        System.out.println("Ingresa la base: ");
               
                              String base=Option.readLine();
                 
                              int B1=Integer.parseInt(base);
                             
                        System.out.println("Ingresa la altura: ");
               
                              String altura=Option.readLine();
                 
                              int H1=Integer.parseInt(altura);
                 
                        System.out.println("El area del triangulo es igual a: " + ((H1*B1)/2));                      
                           
                       break;
                   
                     case 2:
                                                                             
                        System.out.println("Ingresa la base: ");
               
                              String bas=Option.readLine();
                 
                              int RB=Integer.parseInt(bas);
                             
                        System.out.println("Ingresa la altura: ");
               
                              String altur=Option.readLine();
                 
                              int RH=Integer.parseInt(altur);
                 
                        System.out.println("El area del rectangulo es igual a: " + (RB*RH));                      
           
                       
                       break;
                                           
                     case 3:
                       
                        System.out.println("Ingresa el radio: ");
               
                              String radio=Option.readLine();
                 
                              int R1=Integer.parseInt(radio);
                             
                        System.out.println("El area del circulo es igual a: " + (3.14*R1*R1));                      
           
                       break;
                     
                     case 4:
       
                        System.out.println("Ingresa la medida de un lado: ");
               
                              String lado=Option.readLine();
                 
                              int L1=Integer.parseInt(lado);
                             
                        System.out.println("El area del cuadrado es igual a: " + (L1*L1));                      
           
                       
                       break;
                   
                     default:
                                           
                        System.out.println("OpCiOn InCoRrEcTa");
                       
                       break;
       
                               }
                   
                   
                       
        }
}

Conversión Número Letra con Switch


/* Conversion Numero Letra con Switch
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS           *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ            *
                                      *  ErNeStO rOsAlEs CaRlOs                                          *
                                      *  ernestorosales@live.com                                              *
                                      *********************************************
*/

import java.io.*;

class SwitchConversionNumeroLetra

{
     
        public static void main (String args []) throws IOException
             
        {
             
                BufferedReader Numbers=new BufferedReader (new InputStreamReader (System.in));
             
                System.out.println("Ingresa un numero del 1 al 10: ");
             
                  String nn1=Numbers.readLine();
               
                  int Number=Integer.parseInt(nn1);
               
               
     
                   switch(Number)
                     
                   {
                   
                     case 1:
                        System.out.println("UnO");
                     
                       break;
                   
                     case 2:
                                                                             
                        System.out.println("DoS");
                     
                       break;
                                         
                     case 3:
                     
                        System.out.println("TrEs");
                     
                       break;
                     
                     case 4:
     
                        System.out.println("CuAtRo");
                     
                       break;
                     
                     case 5:
                         
                        System.out.println("CiNcO");
                     
                       break;
                     
                     case 6:
                     
                      System.out.println("SeIs");
                     
                       break;
                     
                     case 7:
                     
                      System.out.println("SiEtE");
                     
                       break;

                     case 8:
                     
                      System.out.println("OcHo");
                     
                       break;

                     case 9:
                     
                      System.out.println("NuEvE");
                     
                       break;

                     case 10:
                     
                      System.out.println("DiEz");
                     
                       break;
                                                                   

                     default:
                                         
                        System.out.println("OpCiOn InCoRrEcTa");
                     
                       break;
     
                               }
                 
                   
                       
        }
}

Vocales Minuscula Mayuscula con Switch


/* Vocales Minuscula Mayuscula con Switch
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS            *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ             *
                                      *  ErNeStO rOsAlEs CaRlOs                                           *
                                      *  ernestorosales@live.com                                               *
                                      *********************************************
*/

import java.io.*;

class SwitchVocalMinusculaMayuscula

{
       
        public static void main (String args []) throws IOException
               
        {
               
                BufferedReader Vocal=new BufferedReader (new InputStreamReader (System.in));
               
                System.out.println("Ingresa una vocal en minuscula: ");
               
                  String vO=Vocal.readLine();
                 
                  char V1=vO.charAt(0);
                           
       
                   switch(V1)
                       
                   {
                   
                     case 'a':  
                        System.out.println("Vocal: A");
                       
                       break;
                   
                     case 'e':
                                                                             
                        System.out.println("Vocal: E");
                       
                       break;
                                           
                     case 'i':
                       
                        System.out.println("Vocal: I");
                     
                       break;
                     
                     case 'o':
       
                        System.out.println("Vocal: O");
                       
                       break;
                     
                     case 'u':
                           
                        System.out.println("Vocal: U");
                     
                       break;
                   
                     default:
                                           
                        System.out.println("OpCiOn InCoRrEcTa");
                       
                       break;
       
                               }
                   
                   
                       
        }
}

Dias de Semana con Switch


/* Dias de Semana con Switch
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS           *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ             *
                                      *  ErNeStO rOsAlEs CaRlOs                                          *
                                      *  ernestorosales@live.com                                              *
                                      *********************************************
*/


import java.io.*;

class SwitchDiasSemana

{
       
        public static void main (String args []) throws IOException
               
        {
               
                BufferedReader TheDays=new BufferedReader (new InputStreamReader (System.in));
               
                System.out.println("Ingresa un numero del 1 al 7: ");
               
                  String nn1=TheDays.readLine();
                 
                  int Day=Integer.parseInt(nn1);
                 
                 
       
                   switch(Day)
                       
                   {
                   
                     case 1:  
                        System.out.println("LuNeS");
                       
                       break;
                   
                     case 2:
                                                                             
                        System.out.println("MaRtEs");
                       
                       break;
                                           
                     case 3:
                       
                        System.out.println("MiErCoLeS");
                     
                       break;
                     
                     case 4:
       
                        System.out.println("JuEvEs");
                       
                       break;
                     
                     case 5:
                           
                        System.out.println("ViErNeS");
                     
                       break;
                     
                     case 6:
                     
                      System.out.println("SaBaDo");
                     
                       break;
                     
                     case 7:
                     
                      System.out.println("DoMiNgO");
                     
                       break;
                     
                     default:
                                           
                        System.out.println("OpCiOn InCoRrEcTa");
                       
                       break;
       
                               }
                   
                   
                       
        }
}

Intercalacion Directa Ernesto Rosales


/* Metodo de Intercalacion Directa.
 *
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS   *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ  *
                                      *  EsTrUcTuRa De DaToS                      *
                                      *  ErNeStO rOsAlEs CaRlOs                   *
                                      *  ernestorosales@live.com                  *
                                      *********************************************
*/

import java.io.*;
import java.awt.*;


public class IntercalacionDirectaErnestoRosales
{
       
private static void Inter(int[] Arreglo1, int[] Arreglo2, int[] Arreglo3) // Metodo Inter con tres arreglos.
{
int Indice1=0; // Declaracion de posiciones de arreglo.
int Indice2=0;
int Indice3=0;

while(Indice1<Arreglo1.length && Indice2<Arreglo2.length) // Mientras la variable Indice1 y 2 sean de menor longitud
{                                                         // que el tamano del arreglo 1 y 2.
if(Arreglo1[Indice1]<Arreglo2[Indice2])  // Si el arreglo en posicion 0 es menor que el arreglo 2 en posicion 0
{
Arreglo3[Indice3]=Arreglo1[Indice1] ;  // Almacena el dato del arreglo1 en el arreglo3.
Indice1++;
}

else
{
Arreglo3[Indice3]=Arreglo2[Indice2];      // Si no almacena el dato de arreglo2 en arreglo3.
Indice2++;
}
Indice3++;
}
if(Indice1<Arreglo1.length)  // Si valor de Indice1 es menor al tamano del arreglo1.
System.arraycopy(Arreglo1,Indice1,Arreglo3,Indice3,Arreglo1.length-Indice1);
/*
*Copiar dos arrays en uno con Java (arraycopy).
*
  Los parámetros que recibe el método Java .arrayCopy son:

* Array origen
* Posición inicial del array origen
* Array destino
* Posición incial en el array de destino
* Numero de elementos a copiar del array origen al array destino
*/
else
System.arraycopy(Arreglo2,Indice2,Arreglo3,Indice3,Arreglo2.length-Indice2);
}

public static void erc(int arre[]) // Metodo erc, con el argumento arre[](un arreglo).
{
if(arre.length<=1) // Si el tamano del arreglo es igual o mayor a 1.
return;

int tamano1=arre.length/2; // Divide el arreglo en dos partes.
int tamano2=arre.length-tamano1;

int PrimeraMitad[]=new int[tamano1]; // Declara dos arreglos con el tamano antes dividido.
int SegundaMitad[]=new int[tamano2];

System.arraycopy(arre,0,PrimeraMitad,0,tamano1); // Inserto primera mitad de datos en arreglo PrimeraMitad
System.arraycopy(arre,tamano1,SegundaMitad,0,tamano2); // Inserto segunda mitad de datos en arreglo SegundaMitad.

erc(PrimeraMitad);
erc(SegundaMitad);

IntercalacionDirectaErnestoRosales.Inter(PrimeraMitad,SegundaMitad,arre); // Relacion de metodo IDER e Inter. con
}  // atributos PM,SM y arre.

public static void main(String args[])throws IOException
{

BufferedReader erc=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Tamano de vector"); // Pido tamano de vector desde teclado.
int t=Integer.parseInt(erc.readLine());

int[] v=new int[t];

System.out.println("\nIngresa datos\n"); // Solicito que usuario ingrese datos.
for(int i=0;i<t;i++)
{
try{

System.out.println("Dato "+(i+1)+ ":");
v[i]=Integer.parseInt(erc.readLine());
}

catch(Exception e) // Exepcion en caso de que no ingrese numero.
{
System.out.println("Numero");
}
}

IntercalacionDirectaErnestoRosales.erc(v);

System.out.println("Vector ordenado: "); // Imprimo datos ordenados.

for(int i=0;i<t;i++)
{
System.out.println(" " + v[i]);
}
}



}

Intercalacion Directa Swing


/* Proyecto Final de las materias Topicos Selectos de Programacion y Estructura de Datos/
 * Programa de intercalacion directa en swing.
 * Fuente:   .....------          Conocimientos adquiridos e investigacion en distintas fuentes          ------.....

                                      *********************************************
                                      *  InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS   *
                                      *  InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ  *
                                      *  EsTrUcTuRa De DaToS                      *
                                      *  ErNeStO rOsAlEs CaRlOs                   *
                                      *  ernestorosales@live.com                  *
                                      *********************************************
*/


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class IntercalacionDirectaSwing extends JFrame
{
JLabel l1,l2;
JTextField t1;
JButton b1;

public IntercalacionDirectaSwing()
{
setSize(300,350);
setTitle("Intercalacion Directa");
setVisible(true);
setDefaultCloseOperation(HIDE_ON_CLOSE);
setLocationRelativeTo(null);

Container contenedor=getContentPane();
contenedor.setLayout(new FlowLayout());

l1=new JLabel("Programa de Intercalacion Directa");
contenedor.add(l1);

l2=new JLabel("Tamano de vector");
contenedor.add(l2);

t1=new JTextField(10);
contenedor.add(t1);

b1=new JButton("HaCeR");
contenedor.add(b1);

ManejadorCamposTexto m=new ManejadorCamposTexto();
b1.addActionListener(m);

}

private static void Inter(int[] Arreglo1, int[] Arreglo2, int[] Arreglo3)
{
int Indice1=0;
int Indice2=0;
int Indice3=0;

while(Indice1<Arreglo1.length && Indice2<Arreglo2.length)
{
if(Arreglo1[Indice1]<Arreglo2[Indice2])
{
Arreglo3[Indice3]=Arreglo1[Indice1] ;
Indice1++;
}

else
{
Arreglo3[Indice3]=Arreglo2[Indice2];
Indice2++;
}
Indice3++;
}
if(Indice1<Arreglo1.length)
System.arraycopy(Arreglo1,Indice1,Arreglo3,Indice3,Arreglo1.length-Indice1);

else
System.arraycopy(Arreglo2,Indice2,Arreglo3,Indice3,Arreglo2.length-Indice2);
}

public static void erc(int arre[])
{
if(arre.length<=1)
return;

int tamano1=arre.length/2;
int tamano2=arre.length-tamano1;

int PrimeraMitad[]=new int[tamano1];
int SegundaMitad[]=new int[tamano2];

System.arraycopy(arre,0,PrimeraMitad,0,tamano1);
System.arraycopy(arre,tamano1,SegundaMitad,0,tamano2);

erc(PrimeraMitad);
erc(SegundaMitad);

IntercalacionDirectaSwing.Inter(PrimeraMitad,SegundaMitad,arre);
}

public static void main (String args[])
{
new IntercalacionDirectaSwing();
}

private class ManejadorCamposTexto implements ActionListener
{
public void actionPerformed(ActionEvent evento)
{
if(evento.getSource()==b1)
{
if(t1.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Ingresa Dato");
}

else
{
String nt=t1.getText();
int t=Integer.parseInt(nt);

int[] v=new int[t];

for(int i=0;i<t;i++)
{
v[i]=Integer.parseInt(JOptionPane.showInputDialog("Ingresa dato "+(i+1)+" : "));
}

t1.setText("");

IntercalacionDirectaSwing.erc(v);

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Codigo obtenido de la pag:
//***************************** http://www.daniweb.com/forums/thread14841.html
//***************************** Permite imprimir el arreglo en un Mensaje de dialogo.

StringBuilder builder = new StringBuilder(v.length);
for (int i=0;i<v.length;builder.append(v[i++])) builder.append(" ");
JOptionPane.showMessageDialog(null, builder.toString(), "Datos en Orden", JOptionPane.INFORMATION_MESSAGE);



}
}
}
}
}