Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class tp3Ej2 {
- public static void main(String[] args) {
- Queue<String> cola1 = new Queue<String>();
- Queue<String> colaAuxiliar = new Queue<String>();
- Scanner entrada = new Scanner(System.in);
- int cont=0;
- while (cont!=3){
- switch(cont){
- case 1:
- cargarCola(cola1,entrada);
- modificarCola(cola1,colaAuxiliar);
- System.out.println(colaAuxiliar.toString());
- case 2:
- }
- cont=Helper.validarNumero(entrada, "'opcion' \n1-Manual \n2-Random \n3-salir");
- }
- }
- public static void cargarCola(Queue<String> cola, Scanner entrada) {
- int cont =1;
- String letra;
- while (cont!=2){
- if (cola.estaLlena()){
- letra=cargarLetra(entrada, "ingresar una letra");
- cola.offer(letra);
- }
- cont=Helper.elegirOpcion(entrada, "'seguir cargando' \n1-Si \n2-No");
- }
- System.out.println("Valores ingresados"+cola.toString());
- }
- public static void modificarCola(Queue<String> cola, Queue<String> colaAuxiliar) {
- String letra;
- boolean continuar = true;
- while(continuar){
- letra=cola.pool();
- if(letra.equalsIgnoreCase("a")){
- colaAuxiliar.offer(letra.toUpperCase());
- }
- else{
- if(letra.equalsIgnoreCase("e")){
- colaAuxiliar.offer(letra.toUpperCase());
- }
- else{
- if(letra.equalsIgnoreCase("i")){
- colaAuxiliar.offer(letra.toUpperCase());
- }
- else{
- if(letra.equalsIgnoreCase("o")){
- colaAuxiliar.offer(letra.toUpperCase());
- }
- else{
- if(letra.equalsIgnoreCase("u")){
- colaAuxiliar.offer(letra.toUpperCase());
- }
- else{
- colaAuxiliar.offer(letra);
- }
- }
- }
- }
- }
- if(cola.estaVacia()){
- continuar=false;
- }
- }
- }
- //validar que se ingrese solamente letras primera parte
- public static String cargarLetra(Scanner entrada,String mensaje){
- System.out.println(mensaje);
- String linea=entrada.nextLine();
- while(validarLetras(linea)||linea.length()<=0){
- System.out.println("''ERROR'' No Ingresar Numeros o mas de un caracter");
- System.out.println(mensaje);
- linea=entrada.nextLine();
- }
- return linea;
- }
- //validar que se ingrese solamente letras segunda parte
- public static boolean validarLetras(String linea) {
- for (int x = 0; x < linea.length(); x++) {
- char c = linea.charAt(x);
- if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment