Roke98

Ejercicio2-Tp3-Unju

Oct 11th, 2022 (edited)
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package Practico3;
  2.  
  3. import java.util.Random;
  4. //import java.util.Queue;
  5.  
  6. public class Ejercicio2 {
  7.     static Random aleatorio = new Random();
  8.     public static void main(String[] args) {
  9.        
  10.         // TODO Auto-generated method stub
  11.         menu();
  12.     }
  13.    
  14.     public static void menu() {
  15.        
  16.         int num,opcion,opcion2;
  17.        
  18.         do {
  19.             Queue<Integer> cola = new Queue<>();
  20.            
  21.             num = Helper.getInteger("Ingrese un valor numerico(entero)");
  22.             System.out.println("Menu Principal");
  23.             System.out.println("-------------------------------------------");
  24.             System.out.println("1- Cargar la Cola de forma Manual");
  25.             System.out.println("2- Cargar la Cola con valores aleatorios");
  26.             System.out.println("-------------------------------------------");
  27.             opcion = Helper.getInteger("Ingrese una opcion");
  28.             switch(opcion) {
  29.             case 1:
  30.                 cola = cargarColaManual(cola);
  31.                 System.out.println("La cola original es :\n" + cola);
  32.                
  33.                 cola = suprimirMultiplso(cola, num);
  34.                 cola = suprimirDivisores(cola, num);
  35.                 System.out.println("La cola eliminando los multiplos y divisores de "+ num + " es " + "\n" +cola);
  36.                 break;
  37.             case 2:
  38.                 cola = cargarColaAleat(cola);
  39.                 System.out.println("La cola original es :\n" + cola);
  40.                
  41.                 cola = suprimirMultiplso(cola, num);
  42.                 cola = suprimirDivisores(cola, num);
  43.                 System.out.println("La cola eliminando los multiplos y divisores de "+ num + " es " + "\n" +cola);
  44.                 break;
  45.             default:
  46.                 System.out.println("opcion no valida");
  47.             }
  48.            
  49.             opcion2 = Helper.getInteger("Cargar otra cola??(Si=1//No=2)");
  50.         }while(opcion2!=2);
  51.         System.out.println("gracias :D");
  52.     }
  53.    
  54.     public static Queue<Integer> suprimirMultiplso(Queue<Integer> cola, int num){
  55.         Queue<Integer> colaMul = new Queue<>(cola.size());
  56.         int aux;
  57.        
  58.         while(!cola.isEmpty()) {
  59.             aux = cola.remove();
  60.             if(!(aux%num==0)) {
  61.                 colaMul.add(aux);
  62.             }
  63.         }
  64.         return colaMul;
  65.     }
  66.    
  67.     public static Queue<Integer> suprimirDivisores(Queue<Integer> cola, int num){
  68.         Queue<Integer> colaDiv = new Queue<>(cola.size());
  69.         int aux;
  70.        
  71.         while (!cola.isEmpty()) {
  72.             aux = cola.remove();
  73.             if (num % aux != 0) {
  74.                 colaDiv.add(aux);
  75.             }
  76.            
  77.         }
  78.         return colaDiv;
  79.     }
  80.    
  81.     public static Queue<Integer> cargarColaManual(Queue<Integer> cola){
  82.         do{
  83.             cola.offer(Helper.getPositiveInt("INGRESE UN NUMERO ENTERO POSITIVO"));
  84.         }while (!cola.isFull());
  85.  
  86.         return cola;
  87.     }
  88.    
  89.     public static Queue<Integer> cargarColaAleat(Queue<Integer> cola){
  90.         for(int i = 0; i<10; i++) {
  91.             cola.offer(aleatorio.nextInt(100));
  92.         }
  93.         return cola;
  94.     }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment