-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiblioteca.java
118 lines (108 loc) · 3.31 KB
/
Biblioteca.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Biblioteca {
ArrayList<Libro> libros;
ArrayList<Revista> revistas;
ArrayList<Autor> autores;
public Biblioteca(String rutaDeLosAutores, String rutaDeEntrada, String rutaDeSalida) {
iniciarLista();
cargarAutores(rutaDeLosAutores);
cargarLibros(rutaDeEntrada);
crearSalida(rutaDeSalida);
}
private String devolverGenerico(Publicacion a) {
return a.getTitulo() + " " + this.autores.get(a.getAutor()-1).retornarNombreCompleto() + " " + a.retornarPrestado();
}
private void crearSalida(String rutaDeSalida) {
PrintWriter pw = null;
try {
pw = new PrintWriter(new File(rutaDeSalida));
int numeroDeWeas = libros.size()+ revistas.size();
pw.println(numeroDeWeas);
ArrayList<Publicacion> publicaciones = new ArrayList<Publicacion>();
publicaciones.addAll(libros);
publicaciones.addAll(revistas);
int x = 1;
for(Publicacion a:publicaciones) {
x++;
pw.println(x + " "+ this.devolverGenerico(a));
}
pw.println();
} catch (Exception e) {
System.out.println(e);
}
if (pw != null) {
try {
pw.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
private void iniciarLista() {
this.libros = new ArrayList<Libro>();
this.revistas = new ArrayList<Revista>();
this.autores = new ArrayList<Autor>();
}
private void agregarLibro(Libro libro) {
this.libros.add(libro);
}
private void agregarRevista(Revista revista) {
this.revistas.add(revista);
}
private void agregarAutor(Autor autores) {
this.autores.add(autores);
}
private void cargarAutores(String rutaDeLosAutores) {
Scanner sc = null;
try {
sc = new Scanner(new File(rutaDeLosAutores));
Integer x = Integer.parseInt(sc.nextLine());
for (int i = 0; i < x; i++) {
String[] lineas = sc.nextLine().split(" ");
this.agregarAutor(new Autor(Integer.parseInt(lineas[0]), lineas[1], lineas[2], lineas[3]));
}
} catch (Exception e) {
System.out.println(e);
}
if (sc != null) {
try {
sc.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
private void cargarLibros(String rutaDeEntrada) {
Scanner sc = null;
try {
sc = new Scanner(new File(rutaDeEntrada));
Integer x = Integer.parseInt(sc.nextLine());
for (int i = 0; i < x; i++) {
String[] lineas = sc.nextLine().split(" ");
this.agregarLibro(new Libro(Long.parseLong(lineas[0]), Integer.parseInt(lineas[1]), Integer.parseInt(lineas[2]), lineas[3], Integer.parseInt(lineas[4]), Integer.parseInt(lineas[5])));
}
x = Integer.parseInt(sc.nextLine());
for (int i = 0; i < x; i++) {
String[] lineas = sc.nextLine().split(" ");
this.agregarRevista(new Revista(lineas[0], Integer.parseInt(lineas[1]), Integer.parseInt(lineas[2]), lineas[3], Integer.parseInt(lineas[4]), Integer.parseInt(lineas[5])));
}
} catch (Exception e) {
System.out.println(e);
}
if (sc != null) {
try {
sc.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
public static void main(String[] args) {
Biblioteca a = new Biblioteca(".//src//objetos2017//PC//POO1//Parcial Nº2//autores.in",
".//src//objetos2017//PC//POO1//Parcial Nº2//biblioteca.in",
".//src//objetos2017//PC//POO1//Parcial Nº2//biblioteca.out");
}
}