Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
- //
- import java.util.Random;
- import java.util.Scanner;
- public class CasoEjemplo_d {
- private static Scanner scanner = new Scanner(System.in);
- public static void main(String[] args) {
- CasoEjemplo_d ejemplo = new CasoEjemplo_d();
- ejemplo.Ejecutar();
- }
- public static Character getCharacter(Scanner scanner, String message) {
- Character ch;
- while (true) {
- System.out.print(message);
- try {
- ch = scanner.nextLine().charAt(0);
- return ch;
- } catch (Exception exception) {
- }
- }
- }
- public void Ejecutar() {
- Libro libro;
- Character option;
- System.out.println("Opciones");
- System.out.println(" 1. Ingresa por consola");
- System.out.println(" 2. Generador aleatorio");
- option = Character.toUpperCase(getCharacter(scanner, "\nSu opción: "));
- switch (option) {
- case '1':
- case '2':
- do {
- libro = (option == '1') ? consoleCreate() : randomCreate();
- System.out.println(libro);
- } while (Character.toUpperCase(getCharacter(scanner, "\nCrea otro libro (S/N): ")) != 'N');
- break;
- }
- }
- public Libro consoleCreate() {
- String titulo;
- String autor;
- String editorial;
- Integer anioPublicacion;
- Double precio;
- System.out.print("Ingrese la información del libro\n");
- System.out.print("Título.............: ");
- titulo = scanner.nextLine();
- System.out.print("Autor..............: ");
- autor = scanner.nextLine();
- System.out.print("Editorial..........: ");
- editorial = scanner.nextLine();
- while (true) {
- try {
- System.out.print("Año de Publicación.: ");
- anioPublicacion = Integer.parseInt(scanner.nextLine());
- if (anioPublicacion < 0) {
- System.out.println("Ingrese un año correcto");
- continue;
- }
- break;
- }
- catch (Exception exception) {
- System.out.println("Ingrese un año correcto");
- }
- }
- while (true) {
- try {
- System.out.print("Precio.............: ");
- precio = Double.parseDouble(scanner.nextLine());
- if (precio < 0.0) {
- System.out.println("Ingrese un precio correcto");
- continue;
- }
- break;
- }
- catch (Exception exception) {
- System.out.println("Ingrese un precio correcto");
- }
- }
- Libro libro = new Libro(titulo, autor, editorial, anioPublicacion, precio);
- return libro;
- }
- public Libro randomCreate() {
- String titulo;
- String autor;
- String editorial;
- Integer anioPublicacion;
- Double precio;
- Random random = new Random();
- titulo = algunosTitulos[random.nextInt(algunosTitulos.length)];
- autor = algunosAutores[random.nextInt(algunosAutores.length)];
- editorial = algunasEditoriales[random.nextInt(algunasEditoriales.length)];
- anioPublicacion = random.nextInt(2020);
- precio = random.nextDouble() * 1000;
- Libro libro = new Libro(titulo, autor, editorial, anioPublicacion, precio);
- return libro;
- }
- private static String[] algunosTitulos = {
- "Foundations of Computer Science. C Edition",
- "Estructura de Datos y Algoritmos",
- "Python no Muerde Yo Sí",
- "Curso Python para Principiantes",
- "Organization and Maintenance of Large Ordered Indexes",
- "Algoritmos y Estructura de Datos",
- "Algorithmics Theory and Practice",
- "Fundamentals of Algorithmics",
- "Introduction to Algorithms",
- "Data Structures and Algorithms in Python",
- "C++ How to Progrmam Instructor's Manual Contents",
- "Cómo Programar en C, C++ y Java",
- "Cómo Programar en C#",
- "Java Cómo Programar",
- "Java How to Program",
- "Data Structures and Algorithms in C++",
- "Thinking in C++, Volume 1",
- "Thinking in C++, Volume 2",
- "Estructuras de datos en Java",
- "Estructura de datos en C++",
- "Algorithm Design",
- "The Art of Computer Programming Volume 1 Fundamental Algorithms 2nd Edition",
- "Learning Python",
- "Programming Python",
- "Introduction to Theory of Computation",
- "Fundamentos de Programación en Java",
- "Handbook of Data Structures and Applications",
- "Open Data Structures (in Java)",
- "The C++ Programming Language",
- "Python Tutorial. Release 3.2.3",
- "El tutorial de Python"
- };
- private static String[] algunosAutores = {
- "Aho, Alfred V",
- "2Ullman, Jeffrey D",
- "Alsina, Roberto",
- "Bahit, Eugenia",
- "Bayer, Rudolf",
- "Brassard, Gilles",
- "Bratley, Paul",
- "Brucker, Peter",
- "Cabanes, Nacho",
- "Christian Charras",
- "Cormen, Thomas H",
- "Deitel, Harvey M",
- "Deitel, Paul J",
- "Drozdek, Adam",
- "Eckel, Bruce",
- "Joyanes Aguilar, Luis",
- "Zahonero Martínez, Ignacio",
- "Knuth Donald E",
- "Lutz, Mark",
- "Morin, Pat",
- "Sedgewick, Robert",
- "Flajolet, Philippe",
- "Skiena, Steven S",
- "Stroustrup, Bjarne",
- "van Rossum, Guido",
- "Wachenchauzer, Rosita"
- };
- private static String[] algunasEditoriales = {
- "Alianza Editorial",
- "Milky Way Edici",
- "Planeta Cómic",
- "Ivrea España",
- "Astiberri Edici",
- "Blackie Books",
- "Editorial Anagr",
- "Nova",
- "Austral Editorial",
- "Alfaguara",
- "Nórdica Libros",
- "Roca Editorial",
- "Alpha Decay",
- "Ediciones Kiwi",
- "Periscopi",
- "Editorial Minú",
- "Zorro Rojo",
- "Gallo Nero Edic",
- "Oreilly",
- "Apress",
- "Packt Publishing",
- "Wrox",
- "Manning Press",
- "Pragmatic BookShelf",
- "SitePoint"
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement