Roke98

Ejercicio6-Tp4-Unju

Oct 29th, 2022 (edited)
1,390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.05 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class Ejercicio6 {
  4.     private static DecimalFormat df = new DecimalFormat("#.00");
  5.     private static ILinkedList<Videos> vids;
  6.     public static void main(String[] args) {
  7.        
  8.         menu();
  9.     }
  10.    
  11.     public static void menu() {
  12.         int opcion;
  13.         vids = new SimpleLinkedList<>();
  14.         do {
  15.             System.out.println("MENU PREINCIPAL");
  16.             System.out.println("---------------------------------------");
  17.             System.out.println("1 - Ingresar manualmente un video");
  18.             System.out.println("2 - Generar aleatoriamente un video");
  19.             System.out.println("3 - Buscar por...");
  20.             System.out.println("4 - Finalizar");
  21.             System.out.println("---------------------------------------");
  22.             opcion = Helper.getPositiveInt("ingrese una opcion");
  23.            
  24.             switch(opcion) {
  25.             case 1:
  26.                 cargarVideo();
  27.                 System.out.println(vids.toString());
  28.                 Helper.espera();
  29.                 break;
  30.             case 2:
  31.                 generarVideo();
  32.                 System.out.println(vids.toString());
  33.                 Helper.espera();
  34.                 break;
  35.             case 3:
  36.                 menu2();
  37.                 break;
  38.             case 4:
  39.                 break;
  40.             default:
  41.                 System.out.println("Opcion erronea");
  42.             }
  43.            
  44.         }while(opcion!=4);
  45.         System.out.println("GRacias :D");
  46.     }
  47.    
  48.     public static void menu2() {
  49.         int opcion;
  50.         if(vids.size()<=0) {
  51.             System.out.println("La lista esta vacia, porfavor agregar videos");
  52.         }else {
  53.             do {
  54.                 System.out.println("MENU DE BUSQUEDA O MOSTRAR POR..");
  55.                 System.out.println("**********************************************");
  56.                 System.out.println("1. Buscar por titulo");
  57.                 System.out.println("2. Mostrar todos los videos de un creador");
  58.                 System.out.println("3. Mostrar una lista con videos aleatorios");
  59.                 System.out.println("4. Mostrar videos con una duracion menor a...");
  60.                 System.out.println("5. retornar");
  61.                 System.out.println("**********************************************");
  62.                 opcion = Helper.getPositiveInt("ingrese una opcion");
  63.                 switch(opcion) {
  64.                 case 1:
  65.                     buscarTitul(vids);
  66.                     Helper.espera();
  67.                     break;
  68.                 case 2:
  69.                     buscarCreador(vids);
  70.                     Helper.espera();
  71.                     break;
  72.                 case 3:
  73.                     listaVidsAleat(vids);
  74.                     Helper.espera();
  75.                     break;
  76.                 case 4:
  77.                     duracion(vids);
  78.                     Helper.espera();
  79.                     break;
  80.                 case 5:
  81.                     break;
  82.                 default:
  83.                         System.out.println("opcion invalida");
  84.                 }
  85.                
  86.             }while(opcion!=5);
  87.         }
  88.  
  89.     }
  90.    
  91.     public static void buscarTitul(ILinkedList<Videos> list) {
  92.         String title;
  93.         float total = 0;
  94.         ILinkedList<Videos>vidsTit;
  95.         vidsTit = new SimpleLinkedList<>();
  96.         System.out.println("Que titulo desea buscar");
  97.         title = Helper.scanner.nextLine();
  98.         for(Videos vids: list) {   
  99.             if(vids.getTitulo().toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u')
  100.                     .contains(title.toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u'))) {
  101.                 vidsTit.addInOrderForVideoTitulo(vids);
  102.             }
  103.         }
  104.         for(Videos vids: vidsTit) {
  105.             total = total + vids.getDuracion();
  106.         }
  107.         if(vidsTit.size()<=0) {
  108.             System.out.println("No se encontraron coincidencias de titulos");
  109.         }else {
  110.             System.out.println(vidsTit.toString());
  111.             System.out.println("En total los videos son " + df.format(total) + " minutos");
  112.         }
  113.     }
  114.    
  115.     public static void buscarCreador(ILinkedList<Videos> list) {
  116.         String cread;
  117.         ILinkedList<Videos>vidsCread = new SimpleLinkedList<>();
  118.        
  119.         System.out.println("Que titulo desea buscar");
  120.         cread = Helper.scanner.nextLine();
  121.         for(Videos vids: list) {
  122.             if(vids.getCreador().toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u')
  123.                     .contains(cread.toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u'))) {
  124.                 vidsCread.addFirst(vids);
  125.             }
  126.         }
  127.         if(vidsCread.size()<=0) {
  128.             System.out.println("No se encontraron videos del autor deseado");
  129.         }else {
  130.             System.out.println(vidsCread.toString());
  131.         }
  132.        
  133.     }
  134.    
  135.     public static void listaVidsAleat(ILinkedList<Videos> list) {
  136.         ILinkedList<Videos> vidsAleat = new SimpleLinkedList<>();
  137.         int numAleatorio1,cantVideos;
  138.         cantVideos = Helper.getPositiveInt("Ingrese la cantidad de videos aleatorios que quiere en su lista");
  139.         if(list.size() < cantVideos) {
  140.             System.out.println("La lista no posee tantos videos. Agregue más videos a la lista!");
  141.         }else {
  142.             for(int i=0;i<cantVideos;i++) {
  143.                 numAleatorio1=Helper.randomInt((list.size()));
  144.                 if(!(vidsAleat.equals((Videos)list.get(numAleatorio1)))) {
  145.                         vidsAleat.addLast((Videos)list.get(numAleatorio1));
  146.                 }
  147.             }
  148.             System.out.println(vidsAleat.toString());
  149.         }
  150.     }
  151.    
  152.     public static void duracion(ILinkedList<Videos> list) {
  153.         int maxDur;
  154.         ILinkedList<Videos>vidDur = new SimpleLinkedList<>();
  155.         maxDur = Helper.getPositiveInt("Ingrese la duracion maxima(en minutos)");
  156.         for(Videos vids: list) {
  157.             if((int)vids.getDuracion() <= maxDur) {
  158.                 vidDur.addFirst(vids);
  159.             }
  160.         }
  161.         if(vidDur.size()<=0) {
  162.             System.out.println("No hay videos con una duracion menora a la solicitada");
  163.         }else {
  164.             System.out.println(vidDur.toString());
  165.         }
  166.     }
  167.  
  168.     public static void cargarVideo() {
  169.         String id, titulo, creador;
  170.         float duracion;
  171.         int opcion, posicion;
  172.         do {
  173.             id = generarId();
  174.             System.out.println("Ingrese el titulo del video");
  175.             titulo = Helper.scanner.nextLine();
  176.             System.out.println("Ingrese el Nombre del creador");
  177.             creador = Helper.scanner.nextLine();
  178.             duracion = Helper.getPositiveFloat("Ingrese la duracion del video");
  179.             if (vids.size()==0) {
  180.                 vids.addFirst(new Videos(id, titulo, creador, duracion));
  181.             }else {
  182.                
  183.                 do {
  184.                     posicion = Helper.getPositiveInt("Ingresar: \n1=Ingresar al principio \n2=Ingresar al final");
  185.                     switch(posicion) {
  186.                     case 1:
  187.                         vids.addFirst(new Videos(id, titulo, creador, duracion));
  188.                         break;
  189.                     case 2:
  190.                         vids.addLast(new Videos(id, titulo, creador, duracion));
  191.                         break;
  192.                     default:
  193.                         System.out.println("Opcion incorrecta");
  194.                     }
  195.                 }while(posicion!=1 && posicion!=2);
  196.                
  197.             }
  198.  
  199.             System.out.println("Video cargado correctamente");
  200.             opcion = Helper.getPositiveInt("Desea cargar otro Video?? Si=1//No=2");
  201.         }while(opcion!=2);
  202.     }
  203.    
  204.     public static void generarVideo() {
  205.         String id, titulo, creador;
  206.         float duracion;
  207.         int opcion, posicion;
  208.         do {
  209.             id = generarId();
  210.             titulo = title[Helper.randomInt(title.length)];
  211.             creador = creator[Helper.randomInt(creator.length)];
  212.             duracion = timing();
  213.             posicion = Helper.randomInt(2)+1;
  214.             if (posicion == 1) {
  215.                 vids.addFirst(new Videos(id, titulo, creador, duracion));
  216.             }else {
  217.                 if (posicion == 2) {
  218.                     vids.addLast(new Videos(id, titulo, creador, duracion));
  219.                 }
  220.             }
  221.             System.out.println("Video generado correctamente");
  222.             opcion = Helper.getPositiveInt("Desea generar otro Video?? Si=1//No=2");
  223.         }while(opcion!=2);
  224.     }
  225.    
  226.     static String generarId() {
  227.         String alfaNum = "abcdefghijklmnñopqrstuvwxyz"+"0123456789";
  228.         StringBuilder idRan;
  229.         int x = 7;
  230.         idRan = new StringBuilder(x);
  231.         for(int i = 0; i<x; i++) {
  232.             int myInd = (int)(alfaNum.length() * Math.random());
  233.             idRan.append(alfaNum.charAt(myInd));
  234.         }
  235.         return idRan.toString();
  236.     }
  237.    
  238.     static String[] title = new String[] {
  239.             "Programación orientada a objetos","Definición de clases y objetos","Instaciación de objetos en java",
  240.             "Clase lista enlazada","Lista enlazada simple","Lista doblemente enlazada","Implementación de clase Queue con SLL",
  241.             "Implementación de clase Stack con SLL"
  242.     };
  243.    
  244.     static String[] creator = new String[] {
  245.             "JTentor","Pildoritas Informaticas","EPeralta","SPerez Ibarra","Leledios"
  246.     };
  247.    
  248.     static float timing() {
  249.         float time,aux2;
  250.         double aux3;
  251.         int aux;
  252.         time = 1 + Helper.randomFloat(30);
  253.         aux = (int)time;
  254.         aux2 = time - aux;
  255.         if(aux2 < 0.6) {
  256.             return time;
  257.         }else {
  258.             if (0.6 < aux2) {
  259.                 aux = aux + 1;
  260.                 aux3 = aux2 - 0.6;
  261.                 time = aux + (float)aux3;
  262.                
  263.             }return time;
  264.         }
  265.        
  266.     }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment