Convertidor ASCII

Este codigo es demasiado enfocado a la programacion estructurada, lo cual lo hace ver como un codigo redundante, sin embargo es interesante observarlo desde el punto de vista dado al uso de los metodos implementados y de algunas tecnicas de programación muy comunes tales como el desarrollo de una interfaz basada en un menu de texto.

   1 
   2 import java.io.BufferedReader;
   3 import java.io.IOException;
   4 import java.io.InputStreamReader;
   5 import java.util.ArrayList;
   6 
   7 /**
   8  * 
   9  * @author Carlos Arturo Gutierrez Alias catudo
  10  *
  11  */
  12 
  13 public class Ascii  {
  14         
  15         /**
  16          * 
  17          * Este programa mete cada caracter de una cadena en un arreglo
  18          * y posteriormente los convierte a codigo Ascci
  19          * 
  20          */
  21         private static ArrayList<String> numeros, letras; 
  22         private  static String cadena1, cadenaB,opcion;
  23         public static void main(String[] args) {
  24                 BufferedReader bu = new BufferedReader(new InputStreamReader(System.in));
  25                  
  26                 
  27                 System.out.println("CONVERTIDOR DE CARACTERES ASCII 1.2 \n************************************");
  28                 
  29                 do{
  30                 System.out.println("Elija la opcion de conversion\n1. String a ASCII \n2. ASCCI a String\n3.Salir"); 
  31                 
  32                  
  33                 try {
  34                         opcion = bu.readLine();
  35                 } catch (IOException e1) {
  36                         // TODO Auto-generated catch block
  37                         System.err.println("Error de lectura y escritura");
  38                 }
  39                 
  40                 
  41                         if (opcion.equals("1")){
  42                                 try {
  43                                         
  44                                         System.out.println("Imprima cadena de Caracteres para Convertir");
  45                                         cadena1=bu.readLine();
  46                                         
  47                                         char[] array= cadena1.toCharArray();
  48                                         for(int i =0; i<=array.length-1; i++){
  49                                                 System.out.println(array[i]+"\t"+"*"+"\t"+(int)array[i]);
  50                                                 
  51                                         }
  52                                         
  53 
  54                                         // otra forma de hacerlo
  55                                         /*
  56                                         byte[] bina= cadena1.getBytes();
  57                                         for(int i =0; i<=bina.length-1; i++){
  58                                                 System.out.println("\n"+bina[i]);
  59                                                 
  60                                         }
  61                                         */
  62                                 } catch (IOException e) {
  63                                         System.out.println("Error de Lectura/Escritura");
  64                                         
  65                                 } 
  66                                 
  67                         }
  68                         else if(opcion.equals("2")){
  69                                 
  70                                 System.out.println("Escriba numero de caracteres para convertir");
  71                                 try {
  72                                         cadenaB=bu.readLine();
  73                                         int numeroB = Integer.parseInt(cadenaB);
  74                                         
  75                                         numeros = new ArrayList();
  76                                         letras = new ArrayList();
  77                                         for (int i=0;i<numeroB; i++){
  78                                                 cadena1=bu.readLine();
  79                                                 int num = Integer.parseInt(cadena1);
  80                                                 String rr =Character.toString((char) num);
  81                                                 numeros.add(rr);
  82                                                 letras.add(cadena1);
  83                                                 
  84                                                 
  85                                                 
  86                                                 
  87                                         }
  88                                         
  89                                         
  90                                         
  91                                         
  92                                         
  93                                         
  94                                         
  95                                 } catch (Exception e) {
  96                                         // TODO Auto-generated catch block
  97                                         System.err.println("Error de lectura y escritura o de Formato ");
  98                                         
  99                                 }
 100                                 for(int b=0; b<=numeros.size()-1;b++ ){
 101                                         
 102                                         System.out.println(letras.get(b)+"\t*\t"+numeros.get(b));
 103                                 }
 104                                 
 105                         }
 106                 }
 107                         
 108                 while (!opcion.equals("3"));                    
 109                 
 110         
 111         
 112         }
 113 
 114 
 115 
 116 }
 117 

Java/Programas/ASCII.java (last edited 2008-04-20 14:38:20 by localhost)