-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGestorITV.java
More file actions
107 lines (69 loc) · 2.34 KB
/
GestorITV.java
File metadata and controls
107 lines (69 loc) · 2.34 KB
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
public class GestorITV {
private static Informe[] informes = new Informe[10];
private static Vehiculo[] vehiculos = new Vehiculo[10];
private int numInforme = 0;
public int iniciarProceso(String matricula, Vehiculo.Tipo tipo) {
Vehiculo v = new Vehiculo(matricula, tipo);
int pos = buscarVehiculo(v);
if(pos == -1) {
boolean insertado = false;
for(int i=0; i<10 && !insertado; i++) {
if(vehiculos[i] == null) {
vehiculos[i] = v;
insertado = true;
}
}
}
int posInforme = numInforme;
numInforme++;
informes[posInforme] = new Informe(v, numInforme);
return numInforme;
}
private int buscarVehiculo(Vehiculo v) {
int pos = -1;
for(int i=0; i<10 && pos==-1; i++) {
if(v.equals(vehiculos[i]))
pos = i;
}
return pos;
}
public void cerrarInforme(int id, double gases, boolean cinturones) {
boolean encontrado = false;
boolean hayElementos = true;
for(int i=0; i<10 && !encontrado && hayElementos; i++) {
if(informes[i] != null && informes[i].getId() == id) {
encontrado = true;
informes[i].setInforme(gases,cinturones);
}
if(informes[i] == null)
hayElementos = false;
}
}
public static void main(String[] args) {
GestorITV itv = new GestorITV();
Vehiculo v1 = new Vehiculo("3451-GTS", Vehiculo.Tipo.TURISMO);
Vehiculo v2 = new Vehiculo("5558-HYT", Vehiculo.Tipo.CAMION);
vehiculos[0] = v1;
vehiculos[1] = v2;
itv.iniciarProceso("9992-DHT", Vehiculo.Tipo.FURGONETA);
int idTurismo = itv.iniciarProceso("3451-GTS", Vehiculo.Tipo.TURISMO);
int idCamion = itv.iniciarProceso("8811-KRS", Vehiculo.Tipo.CAMION);
itv.cerrarInforme(idTurismo, 3,true);
itv.cerrarInforme(idCamion, 3.1, true);
System.out.println("\n--- VEHICULOS ---\n");
for(int i=0; i<10; i++) {
if(vehiculos[i] != null)
System.out.println(vehiculos[i]);
}
System.out.println("\n--- INFORMES ---\n");
for(int i=0; i<10; i++) {
if(informes[i] != null)
System.out.println(informes[i]);
}
System.out.println("\n--- INFORMES NO FAVORABLES ---\n");
for(int i=0; i<10; i++) {
if(informes[i] != null && !informes[i].pasaInspeccion())
System.out.println(informes[i]);
}
}
}