Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- public class Ejercicio6 {
- private static DecimalFormat df = new DecimalFormat("#.00");
- private static ILinkedList<Videos> vids;
- public static void main(String[] args) {
- menu();
- }
- public static void menu() {
- int opcion;
- vids = new SimpleLinkedList<>();
- do {
- System.out.println("MENU PREINCIPAL");
- System.out.println("---------------------------------------");
- System.out.println("1 - Ingresar manualmente un video");
- System.out.println("2 - Generar aleatoriamente un video");
- System.out.println("3 - Buscar por...");
- System.out.println("4 - Finalizar");
- System.out.println("---------------------------------------");
- opcion = Helper.getPositiveInt("ingrese una opcion");
- switch(opcion) {
- case 1:
- cargarVideo();
- System.out.println(vids.toString());
- Helper.espera();
- break;
- case 2:
- generarVideo();
- System.out.println(vids.toString());
- Helper.espera();
- break;
- case 3:
- menu2();
- break;
- case 4:
- break;
- default:
- System.out.println("Opcion erronea");
- }
- }while(opcion!=4);
- System.out.println("GRacias :D");
- }
- public static void menu2() {
- int opcion;
- if(vids.size()<=0) {
- System.out.println("La lista esta vacia, porfavor agregar videos");
- }else {
- do {
- System.out.println("MENU DE BUSQUEDA O MOSTRAR POR..");
- System.out.println("**********************************************");
- System.out.println("1. Buscar por titulo");
- System.out.println("2. Mostrar todos los videos de un creador");
- System.out.println("3. Mostrar una lista con videos aleatorios");
- System.out.println("4. Mostrar videos con una duracion menor a...");
- System.out.println("5. retornar");
- System.out.println("**********************************************");
- opcion = Helper.getPositiveInt("ingrese una opcion");
- switch(opcion) {
- case 1:
- buscarTitul(vids);
- Helper.espera();
- break;
- case 2:
- buscarCreador(vids);
- Helper.espera();
- break;
- case 3:
- listaVidsAleat(vids);
- Helper.espera();
- break;
- case 4:
- duracion(vids);
- Helper.espera();
- break;
- case 5:
- break;
- default:
- System.out.println("opcion invalida");
- }
- }while(opcion!=5);
- }
- }
- public static void buscarTitul(ILinkedList<Videos> list) {
- String title;
- float total = 0;
- ILinkedList<Videos>vidsTit;
- vidsTit = new SimpleLinkedList<>();
- System.out.println("Que titulo desea buscar");
- title = Helper.scanner.nextLine();
- for(Videos vids: list) {
- if(vids.getTitulo().toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u')
- .contains(title.toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u'))) {
- vidsTit.addInOrderForVideoTitulo(vids);
- }
- }
- for(Videos vids: vidsTit) {
- total = total + vids.getDuracion();
- }
- if(vidsTit.size()<=0) {
- System.out.println("No se encontraron coincidencias de titulos");
- }else {
- System.out.println(vidsTit.toString());
- System.out.println("En total los videos son " + df.format(total) + " minutos");
- }
- }
- public static void buscarCreador(ILinkedList<Videos> list) {
- String cread;
- ILinkedList<Videos>vidsCread = new SimpleLinkedList<>();
- System.out.println("Que titulo desea buscar");
- cread = Helper.scanner.nextLine();
- for(Videos vids: list) {
- if(vids.getCreador().toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u')
- .contains(cread.toLowerCase().replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u'))) {
- vidsCread.addFirst(vids);
- }
- }
- if(vidsCread.size()<=0) {
- System.out.println("No se encontraron videos del autor deseado");
- }else {
- System.out.println(vidsCread.toString());
- }
- }
- public static void listaVidsAleat(ILinkedList<Videos> list) {
- ILinkedList<Videos> vidsAleat = new SimpleLinkedList<>();
- int numAleatorio1,cantVideos;
- cantVideos = Helper.getPositiveInt("Ingrese la cantidad de videos aleatorios que quiere en su lista");
- if(list.size() < cantVideos) {
- System.out.println("La lista no posee tantos videos. Agregue más videos a la lista!");
- }else {
- for(int i=0;i<cantVideos;i++) {
- numAleatorio1=Helper.randomInt((list.size()));
- if(!(vidsAleat.equals((Videos)list.get(numAleatorio1)))) {
- vidsAleat.addLast((Videos)list.get(numAleatorio1));
- }
- }
- System.out.println(vidsAleat.toString());
- }
- }
- public static void duracion(ILinkedList<Videos> list) {
- int maxDur;
- ILinkedList<Videos>vidDur = new SimpleLinkedList<>();
- maxDur = Helper.getPositiveInt("Ingrese la duracion maxima(en minutos)");
- for(Videos vids: list) {
- if((int)vids.getDuracion() <= maxDur) {
- vidDur.addFirst(vids);
- }
- }
- if(vidDur.size()<=0) {
- System.out.println("No hay videos con una duracion menora a la solicitada");
- }else {
- System.out.println(vidDur.toString());
- }
- }
- public static void cargarVideo() {
- String id, titulo, creador;
- float duracion;
- int opcion, posicion;
- do {
- id = generarId();
- System.out.println("Ingrese el titulo del video");
- titulo = Helper.scanner.nextLine();
- System.out.println("Ingrese el Nombre del creador");
- creador = Helper.scanner.nextLine();
- duracion = Helper.getPositiveFloat("Ingrese la duracion del video");
- if (vids.size()==0) {
- vids.addFirst(new Videos(id, titulo, creador, duracion));
- }else {
- do {
- posicion = Helper.getPositiveInt("Ingresar: \n1=Ingresar al principio \n2=Ingresar al final");
- switch(posicion) {
- case 1:
- vids.addFirst(new Videos(id, titulo, creador, duracion));
- break;
- case 2:
- vids.addLast(new Videos(id, titulo, creador, duracion));
- break;
- default:
- System.out.println("Opcion incorrecta");
- }
- }while(posicion!=1 && posicion!=2);
- }
- System.out.println("Video cargado correctamente");
- opcion = Helper.getPositiveInt("Desea cargar otro Video?? Si=1//No=2");
- }while(opcion!=2);
- }
- public static void generarVideo() {
- String id, titulo, creador;
- float duracion;
- int opcion, posicion;
- do {
- id = generarId();
- titulo = title[Helper.randomInt(title.length)];
- creador = creator[Helper.randomInt(creator.length)];
- duracion = timing();
- posicion = Helper.randomInt(2)+1;
- if (posicion == 1) {
- vids.addFirst(new Videos(id, titulo, creador, duracion));
- }else {
- if (posicion == 2) {
- vids.addLast(new Videos(id, titulo, creador, duracion));
- }
- }
- System.out.println("Video generado correctamente");
- opcion = Helper.getPositiveInt("Desea generar otro Video?? Si=1//No=2");
- }while(opcion!=2);
- }
- static String generarId() {
- String alfaNum = "abcdefghijklmnñopqrstuvwxyz"+"0123456789";
- StringBuilder idRan;
- int x = 7;
- idRan = new StringBuilder(x);
- for(int i = 0; i<x; i++) {
- int myInd = (int)(alfaNum.length() * Math.random());
- idRan.append(alfaNum.charAt(myInd));
- }
- return idRan.toString();
- }
- static String[] title = new String[] {
- "Programación orientada a objetos","Definición de clases y objetos","Instaciación de objetos en java",
- "Clase lista enlazada","Lista enlazada simple","Lista doblemente enlazada","Implementación de clase Queue con SLL",
- "Implementación de clase Stack con SLL"
- };
- static String[] creator = new String[] {
- "JTentor","Pildoritas Informaticas","EPeralta","SPerez Ibarra","Leledios"
- };
- static float timing() {
- float time,aux2;
- double aux3;
- int aux;
- time = 1 + Helper.randomFloat(30);
- aux = (int)time;
- aux2 = time - aux;
- if(aux2 < 0.6) {
- return time;
- }else {
- if (0.6 < aux2) {
- aux = aux + 1;
- aux3 = aux2 - 0.6;
- time = aux + (float)aux3;
- }return time;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment