Leonel_G

Tp3Ej2

Oct 12th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.28 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class tp3Ej2 {
  4.     public static void main(String[] args) {
  5.         Queue<String> cola1 = new Queue<String>();
  6.         Queue<String> colaAuxiliar = new Queue<String>();
  7.         Scanner entrada = new Scanner(System.in);
  8.         int cont=0;
  9.         while (cont!=3){
  10.             switch(cont){
  11.                 case 1:
  12.                     cargarCola(cola1,entrada);
  13.                     modificarCola(cola1,colaAuxiliar);
  14.                     System.out.println(colaAuxiliar.toString());
  15.                 case 2:
  16.             }
  17.             cont=Helper.validarNumero(entrada, "'opcion' \n1-Manual \n2-Random \n3-salir");
  18.         }
  19.     }
  20.  
  21.  
  22.     public static void cargarCola(Queue<String> cola, Scanner entrada) {
  23.         int cont =1;
  24.         String letra;
  25.         while (cont!=2){
  26.             if (cola.estaLlena()){
  27.                 letra=cargarLetra(entrada, "ingresar una letra");
  28.                 cola.offer(letra);
  29.             }
  30.             cont=Helper.elegirOpcion(entrada, "'seguir cargando' \n1-Si \n2-No");
  31.         }
  32.         System.out.println("Valores ingresados"+cola.toString());
  33.     }
  34.  
  35.     public static void modificarCola(Queue<String> cola, Queue<String> colaAuxiliar) {
  36.         String letra;
  37.         boolean continuar = true;
  38.         while(continuar){
  39.             letra=cola.pool();
  40.             if(letra.equalsIgnoreCase("a")){
  41.                 colaAuxiliar.offer(letra.toUpperCase());
  42.             }
  43.             else{
  44.                 if(letra.equalsIgnoreCase("e")){
  45.                     colaAuxiliar.offer(letra.toUpperCase());
  46.                 }
  47.                 else{
  48.                     if(letra.equalsIgnoreCase("i")){
  49.                         colaAuxiliar.offer(letra.toUpperCase());
  50.                     }
  51.                     else{
  52.                         if(letra.equalsIgnoreCase("o")){
  53.                             colaAuxiliar.offer(letra.toUpperCase());
  54.                         }
  55.                         else{
  56.                             if(letra.equalsIgnoreCase("u")){
  57.                                 colaAuxiliar.offer(letra.toUpperCase());
  58.                             }
  59.                             else{
  60.                                 colaAuxiliar.offer(letra);
  61.                             }
  62.                         }
  63.                     }
  64.                 }
  65.             }
  66.             if(cola.estaVacia()){
  67.                 continuar=false;
  68.             }
  69.         }
  70.        
  71.     }
  72.  
  73.     //validar que se ingrese solamente letras primera parte
  74.     public static String cargarLetra(Scanner entrada,String mensaje){
  75.         System.out.println(mensaje);
  76.         String linea=entrada.nextLine();
  77.         while(validarLetras(linea)||linea.length()<=0){
  78.             System.out.println("''ERROR'' No Ingresar Numeros o mas de un caracter");
  79.             System.out.println(mensaje);
  80.             linea=entrada.nextLine();
  81.         }
  82.         return linea;
  83.     }
  84.     //validar que se ingrese solamente letras segunda parte
  85.     public static boolean validarLetras(String linea) {
  86.         for (int x = 0; x < linea.length(); x++) {
  87.             char c = linea.charAt(x);
  88.             if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
  89.                 return true;
  90.             }
  91.         }
  92.         return false;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment