Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Awes0meM4n
AsistenciaMotor
Commits
88e5478b
Commit
88e5478b
authored
3 years ago
by
Awes0meM4n
Browse files
Options
Download
Email Patches
Plain Diff
Practica finalizada
parent
8b9ae9b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
25 deletions
+34
-25
src/es/mde/App.java
src/es/mde/App.java
+10
-22
src/es/mde/taller/Taller.java
src/es/mde/taller/Taller.java
+24
-3
No files found.
src/es/mde/App.java
View file @
88e5478b
package
es.mde
;
import
java.time.LocalDate
;
import
java.time.chrono.ChronoLocalDate
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
es.mde.taller.Averia
;
import
es.mde.taller.HojaDeTrabajo
;
...
...
@@ -79,40 +75,32 @@ public class App {
hojasDeTrabajo
.
forEach
(
System
.
out
::
println
);
// Para el punto 4
System
.
out
.
println
(
"\n----- PUNTO 4 -----"
);
HojaDeTrabajo
hojaAntigua
=
new
HojaDeTrabajo
(
coche2
,
LocalDate
.
of
(
2021
,
6
,
1
));
Averia
averiaAntigua
=
new
Averia
(
"Cambio de aceite"
,
1
,
filtro
,
new
Repuesto
(
2
,
"1l aceite"
,
50
));
hojasDeTrabajo
.
add
(
hojaAntigua
);
hojaAntigua
.
addReparacionFinalizada
(
averiaAntigua
);
// Momento actual
coche2
.
addAveria
(
averia
);
coche2
.
addAveria
(
averia2
);
// Busco entre las hojas de trabajo las de este coche
// Collection<HojaDeTrabajo> hojasDelCoche = taller.getHojasDeTrabajoParaReparable(coche2);
// Ahora cojo las del ultimo ano
Collection
<
HojaDeTrabajo
>
hojasHaceUnAno
=
taller
.
getHojasHastaHaceUnAno
(
hojaDeTrabajoActual
.
getFechaEntrada
(),
coche2
);
hojasHaceUnAno
.
remove
(
hojaDeTrabajoActual
);
Collection
<
HojaDeTrabajo
>
hojasHaceUnAno
=
taller
.
getHojasHastaHaceUnAno
(
hojaDeTrabajoActual
);
System
.
out
.
println
(
"Encontradas "
+
hojasHaceUnAno
.
size
()
+
" hojas del coche "
+
coche2
);
hojasHaceUnAno
.
forEach
(
System
.
out
::
println
);
// Miro si coincide la averia
Averia
averiaGarantizada
=
null
;
for
(
HojaDeTrabajo
hojaDeTrabajo
:
hojasHaceUnAno
)
{
for
(
Averia
averiaArreglada
:
hojaDeTrabajo
.
getAveriasArregladas
())
{
if
(
hojaDeTrabajoActual
.
getReparable
().
getAverias
().
contains
(
averiaArreglada
))
{
averiaGarantizada
=
averiaArreglada
;
break
;
}
}
if
(
averiaGarantizada
!=
null
)
{
break
;
}
}
System
.
out
.
println
(
"Esta en garantia "
+
averiaGarantizada
);
hojasHaceUnAno
.
forEach
(
System
.
out
::
println
);
Collection
<
Averia
>
averiasGarantizadas
=
taller
.
getAveriasGarantizadas
(
hojaDeTrabajoActual
);
System
.
out
.
println
(
"Esta en garantia "
+
averiasGarantizadas
);
System
.
out
.
println
(
cocheParaBuscar
+
" con averias "
+
cocheParaBuscar
.
getAverias
());
System
.
out
.
println
(
cocheParaBuscar
+
" se repara en "
+
cocheParaBuscar
.
getHorasReparacion
()
+
" horas"
);
System
.
out
.
println
(
cocheParaBuscar
+
" cuesta repararlo "
+
(
cocheParaBuscar
.
getCosteReparacion
()
-
taller
.
precioGarantizado
(
hojaDeTrabajoActual
))
+
"€"
);
}
private
static
String
ponmeBonitaExistencia
(
Taller
taller
,
Repuesto
repuesto
)
{
...
...
This diff is collapsed.
Click to expand it.
src/es/mde/taller/Taller.java
View file @
88e5478b
...
...
@@ -65,10 +65,31 @@ public class Taller {
return
hojasDelReparable
;
}
public
List
<
HojaDeTrabajo
>
getHojasHastaHaceUnAno
(
LocalDate
fechaReferencia
,
Reparable
reparable
)
{
LocalDate
fechaHaceUnAno
=
fecha
Referencia
.
minusYears
(
1
);
return
getHojasDeTrabajoParaReparable
(
r
eparable
).
stream
()
public
List
<
HojaDeTrabajo
>
getHojasHastaHaceUnAno
(
HojaDeTrabajo
hojaDeReferencia
)
{
LocalDate
fechaHaceUnAno
=
hojaDe
Referencia
.
getFechaEntrada
().
minusYears
(
1
);
List
<
HojaDeTrabajo
>
hojasHaceUnAno
=
getHojasDeTrabajoParaReparable
(
hojaDeReferencia
.
getR
eparable
()
).
stream
()
.
filter
(
h
->
h
.
getFechaEntrada
().
isAfter
(
fechaHaceUnAno
))
.
collect
(
Collectors
.
toList
());
hojasHaceUnAno
.
remove
(
hojaDeReferencia
);
return
hojasHaceUnAno
;
}
public
Collection
<
Averia
>
getAveriasGarantizadas
(
HojaDeTrabajo
hojaDeReferencia
)
{
Collection
<
Averia
>
averiasGarantizadas
=
new
ArrayList
<
Averia
>();
for
(
HojaDeTrabajo
hojaDeTrabajo
:
getHojasHastaHaceUnAno
(
hojaDeReferencia
))
{
for
(
Averia
averiaArreglada
:
hojaDeTrabajo
.
getAveriasArregladas
())
{
if
(
hojaDeReferencia
.
getReparable
().
getAverias
().
contains
(
averiaArreglada
))
{
averiasGarantizadas
.
add
(
averiaArreglada
);
}
}
}
return
averiasGarantizadas
;
}
public
float
precioGarantizado
(
HojaDeTrabajo
hojaDeReferencia
)
{
return
(
float
)
getAveriasGarantizadas
(
hojaDeReferencia
).
stream
()
.
mapToDouble
(
Averia:
:
getPrecio
)
.
sum
();
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment