Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Practico3;
- import java.util.Random;
- //import java.util.Queue;
- public class Ejercicio2 {
- static Random aleatorio = new Random();
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- menu();
- }
- public static void menu() {
- int num,opcion,opcion2;
- do {
- Queue<Integer> cola = new Queue<>();
- num = Helper.getInteger("Ingrese un valor numerico(entero)");
- System.out.println("Menu Principal");
- System.out.println("-------------------------------------------");
- System.out.println("1- Cargar la Cola de forma Manual");
- System.out.println("2- Cargar la Cola con valores aleatorios");
- System.out.println("-------------------------------------------");
- opcion = Helper.getInteger("Ingrese una opcion");
- switch(opcion) {
- case 1:
- cola = cargarColaManual(cola);
- System.out.println("La cola original es :\n" + cola);
- cola = suprimirMultiplso(cola, num);
- cola = suprimirDivisores(cola, num);
- System.out.println("La cola eliminando los multiplos y divisores de "+ num + " es " + "\n" +cola);
- break;
- case 2:
- cola = cargarColaAleat(cola);
- System.out.println("La cola original es :\n" + cola);
- cola = suprimirMultiplso(cola, num);
- cola = suprimirDivisores(cola, num);
- System.out.println("La cola eliminando los multiplos y divisores de "+ num + " es " + "\n" +cola);
- break;
- default:
- System.out.println("opcion no valida");
- }
- opcion2 = Helper.getInteger("Cargar otra cola??(Si=1//No=2)");
- }while(opcion2!=2);
- System.out.println("gracias :D");
- }
- public static Queue<Integer> suprimirMultiplso(Queue<Integer> cola, int num){
- Queue<Integer> colaMul = new Queue<>(cola.size());
- int aux;
- while(!cola.isEmpty()) {
- aux = cola.remove();
- if(!(aux%num==0)) {
- colaMul.add(aux);
- }
- }
- return colaMul;
- }
- public static Queue<Integer> suprimirDivisores(Queue<Integer> cola, int num){
- Queue<Integer> colaDiv = new Queue<>(cola.size());
- int aux;
- while (!cola.isEmpty()) {
- aux = cola.remove();
- if (num % aux != 0) {
- colaDiv.add(aux);
- }
- }
- return colaDiv;
- }
- public static Queue<Integer> cargarColaManual(Queue<Integer> cola){
- do{
- cola.offer(Helper.getPositiveInt("INGRESE UN NUMERO ENTERO POSITIVO"));
- }while (!cola.isFull());
- return cola;
- }
- public static Queue<Integer> cargarColaAleat(Queue<Integer> cola){
- for(int i = 0; i<10; i++) {
- cola.offer(aleatorio.nextInt(100));
- }
- return cola;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment