Advertisement
LEANDRONIEVA

Ejercicio6Tp1

Sep 15th, 2022 (edited)
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.89 KB | None | 0 0
  1. package tp1;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import tp0.Helper;
  7.  
  8. public class Tp1ejercicio6 {
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.        
  13.         System.out.println("Ejercicio 6 Tp 1");
  14.         System.out.println("En esta ocación vamos a crear una biblioteca de libros :D");
  15.  
  16.  
  17.         int n =  Helper.getPositiveInt("Indique la cantidad de libros que desea crear");
  18.         Libro[] biblioteca = new Libro[n];
  19.  
  20.         biblioteca = opcion(n);
  21.            
  22.         System.out.println("Libros en la biblioteca: ");
  23.         for (Libro libro : biblioteca) {
  24.             System.out.println(libro);
  25.         }
  26.     }
  27.    
  28.     public static int menu() {
  29.         System.out.println("Desea ingresar un libro manualmente o generarlo aleatoriamente?");
  30.         System.out.println("1. Aleatorio");
  31.         System.out.println("2. Manual");
  32.         System.out.println("3. Salir");
  33.        
  34.         int opcion = Helper.getInteger("Ingrese una opción","Ingrese un número ");
  35.        
  36.         return opcion;
  37.     }
  38.    
  39.     public static Libro[] opcion(int n) {
  40.         int op = 0;
  41.         Libro[] libros = new Libro[n];     
  42.         Libro libro = new Libro();
  43.        
  44.  
  45.         while(op!=1&op!=2&op!=3) {
  46.             op = menu();
  47.  
  48.             switch (op) {
  49.             case 1:                
  50.                 for (int i = 0;i<n;i++) {
  51.                     libro = aleatorio();
  52.                     libros[i] = libro;
  53.                 }
  54.  
  55.                 break;
  56.  
  57.             case 2:
  58.                 libros = new Libro[n];
  59.                 for (int i = 0;i<n;i++) {
  60.                     libro = manual();
  61.                     libros[i] = libro;
  62.                 }
  63.                 break;
  64.             case 3:
  65.                 System.out.println("Programa Terminado");
  66.                 break;
  67.             default:
  68.                 System.out.println("No es una opción correcta ");
  69.                 break;
  70.             }
  71.         }
  72.  
  73.         return libros;
  74.     }
  75.    
  76.     public static Libro aleatorio() {
  77.         Random ran1 =new Random();
  78.  
  79.         String[] editoriales = {"Acantilado","Aguilar","Akal","Alba","Alfaguara",
  80.                 "Alianza","Almadía","Anagrama","Alción","Amorrortu","Añosluz",
  81.                 "Bajo la luna","CICCUS","Colihue","Común","Continente",    "Dunken",
  82.                 "Edelvives Argentina","EDULP","EDUVIM","En Danza","Entropía",
  83.                 "EUDEBA","Granica", "Ivrea","Mansalva","Rubinzal Culzoni",
  84.                 "Sudamericana","Uranito","Utopía Libros"};
  85.  
  86.         String[] titulos = {"Poema de Gilgamesh","Libro de Job (de la Biblia)","Las mil y una noches",
  87.                 "Saga de Njál","Todo se desmorona","Cuentos infantiles","Divina comedia","Orgullo y prejuicio",
  88.                 "Papá Goriot","Molloy, Malone muere, El Innombrable","Decamerón","Ficciones","Cumbres Borrascosas",
  89.                 "El extranjero","Viaje al fin de la noche", "Don Quijote de la Mancha","Los cuentos de Canterbury",
  90.                 "Nostromo","Grandes Esperanzas","Jacques el fatalista","Berlin Alexanderplatz","Crimen y castigo","El idiota"};
  91.  
  92.         String[] autores = {"Abello","Verano","Ana",
  93.                 "Abril" , "Juan","carlos","Abril" , "Juan Carlos" , "Cullel" , "Diana"
  94.                 ,"Abril", "Fernández Serrato" ,    "Abuín" , "Anxo" , "Pérez", "Rasilla" ,"Soria", "Tomás" , "G.Adonis",
  95.                 "Aganzo" , "Carls", "Aguilar","Marina" , "Jesús Aguiló" , "Josep Lluís","Agustini" , "Delmira",
  96.                 "Alarcos Llorach" , "Emilio","Alas","Leopoldo", "Albero"," Miguel", "Albert", "Mechthild",
  97.                 "Alberti","Rafael", "Alberti" , "Rafael", "León" , "María", "Teresa","Alburquerque", "García" , "Luis",
  98.                 "Alcantarilla" , "María","Aldecoa" , "Ignacio","Aldrete" , "Bernardo","Alegría" , "Claribel",
  99.                 "Aleixandre" , "Vicente","Alemany Bay" , "Carmen","Alemany ", "Carmen" ,"Valero" , "Eva" , "Sanchís" , "Victor",
  100.                 "Alexander" , "Francisco","Allan Poe" , "Edgar","Almuzara ", "Javier",  "Alonso Ares" , "Adolfo"};
  101.  
  102.         String [] generos = {"Narrativo","Dramatico","Lirico"};
  103.        
  104.         Character rpta;
  105.        
  106.         String titulo = titulos[ran1.nextInt(titulos.length)];
  107.  
  108.         ArrayList<String> autor = new ArrayList<String>();
  109.         do {
  110.             autor.add(autores[ran1.nextInt(autores.length)]);
  111.             rpta = Helper.getCharacter("Agregar otro autor a un libro? s/n");
  112.         } while (rpta.equals('s'));
  113.  
  114.         String editorial = editoriales[ran1.nextInt(editoriales.length)];
  115.         int año_publ = ran1.nextInt(52)+1970;
  116.         double precio = ran1.nextInt(3000)+1000;
  117.  
  118.         String genero = generos[ran1.nextInt(generos.length)];
  119.  
  120.  
  121.         Libro libro = new Libro(titulo,autor,genero,editorial,año_publ,precio);      
  122.  
  123.         return libro;
  124.  
  125.     }
  126.    
  127.     public static Libro manual() {
  128.         Helper op = new Helper();
  129.         Libro lib = new Libro();
  130.         ArrayList<String> arrAutores = new ArrayList<String>();
  131.        
  132.         lib.setTitulo(op.getString("Ingrese Titulo del Libro"));
  133.         char rpta = 's';
  134.         while (rpta == 's') {
  135.             arrAutores.add(op.getString("Ingrese autor del Libro"));
  136.             rpta = Helper.getCharacter("Agregar otro autor? s/n");
  137.             if (rpta == 's')System.out.println("Ingrese el autor");
  138.         }
  139.         lib.setAutor(arrAutores);
  140.         lib.setGenero_Lit(op.getString("Ingrese el género literario (n: narrativo, d: dramático, l: lírico)"));
  141.         lib.setEditorial(op.getString("Ingrese la editorial "));
  142.         lib.setAnio_Pub(Helper.getPositiveInt("Ingerese el año de publicación"));
  143.         lib.setPrecio(Helper.getPositiveDouble("Ingerese el precio"));
  144.        
  145.         return lib;
  146.     }
  147.    
  148. }
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement