-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEstante.java
88 lines (83 loc) · 2.23 KB
/
Estante.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
package tema3;
public class Estante {
// Atributos
private int max_libros;
private int dimL;
private int cant_libros;
private Libro vec_libros[]; // Vector de libros
// Constructores - Métodos
public Estante(){
cant_libros = 0;
dimL = 0;
vec_libros = new Libro[max_libros = 20];
}
public Estante(int cant_Espacio){
cant_libros = 0;
dimL = 0;
max_libros = cant_Espacio;
vec_libros = new Libro[max_libros];
}
public int cantLibros(){
return cant_libros;
}
public int cantEspacioEstante(){
return max_libros;
}
public String estaLleno_String(){
String ans;
if (dimL == max_libros){
ans = "El estante esta lleno.";
}
else{
ans = "El estante NO esta lleno aun.";
}
return ans;
}
public boolean estaLleno_Boolean(){
return (dimL == max_libros);
}
public String agregarLibro(Libro book){
String state = "No se pudo agregar el libro. Estante lleno!";
if (!estaLleno_Boolean()){
vec_libros[dimL] = book;
dimL++;
cant_libros++;
state = "El libro fue agregado con exito.";
}
return state;
}
public Libro devolverLibro(String nom_Libro){
// Si en libro es igual al nom y no se termino el vector
Libro book = null;
int i = 0;
boolean encontre = false;
while ((i<max_libros) && (!encontre)){
if (vec_libros[i] != null){
if (nom_Libro.equals(vec_libros[i].getTitulo())){
encontre = true;
book = vec_libros[i];
}
}
i++;
}
return book;
}
private String verLibros(){
String str = "Estante ";
String aux = "";
for (int i = 0; i < max_libros; i++){
if (vec_libros[i] != null){
str += "[";
aux = vec_libros[i].toString();
str += aux +"]";
} else {
str+="[null]";
}
}
return str;
}
@Override
public String toString() {
return verLibros();
}
}