Skip to content
Snippets Groups Projects
Commit 9c36681d authored by victorm's avatar victorm
Browse files

Tipos de Contenedores y Contenedor

parent 56c013cc
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
* @author victorm * @author victorm
*/ */
public abstract class Contenedor { public abstract class Contenedor {
private final List<Trayecto> trayectos = new ArrayList<>(); protected final List<Trayecto> trayectos = new ArrayList<>();
private ISO6346 codigo; private ISO6346 codigo;
private float pesoTara; private float pesoTara;
...@@ -117,12 +117,12 @@ public abstract class Contenedor { ...@@ -117,12 +117,12 @@ public abstract class Contenedor {
* @param costePorMilla El coste por milla recorrida en un trayecto * @param costePorMilla El coste por milla recorrida en un trayecto
* @return el precio total del transporte del contenedor * @return el precio total del transporte del contenedor
*/ */
public double precioTransporteTotalContenedor(double costeDiarioTrayecto, double costePorMilla) { public double precioTransporteTotalContenedor() {
if (this.trayectos.isEmpty()) if (this.trayectos.isEmpty())
return 0.0; return 0.0;
double precioTotal = 0.0; double precioTotal = 0.0;
for (Trayecto t : this.trayectos) { for (Trayecto t : this.trayectos) {
precioTotal += t.precioTrayectoEnEuros(costeDiarioTrayecto, costePorMilla); precioTotal += t.precioTrayectoEnEuros();
} }
return precioTotal; return precioTotal;
} }
...@@ -138,26 +138,26 @@ public abstract class Contenedor { ...@@ -138,26 +138,26 @@ public abstract class Contenedor {
* @throws IllegalStateException si la fecha fin del ultimo trayecto es superior a la de inicio del nuevo trayecto * @throws IllegalStateException si la fecha fin del ultimo trayecto es superior a la de inicio del nuevo trayecto
* @throws IllegalStateException si el puerto/muelle destinos del ultimo trayecto no son los de origen del nuevo. * @throws IllegalStateException si el puerto/muelle destinos del ultimo trayecto no son los de origen del nuevo.
*/ */
public void anyadirTrayecto(Trayecto t) { public abstract void anyadirTrayecto(Trayecto t);
if (t == null)
throw new IllegalArgumentException("El trayecto no puede ser nulo");
if (this.trayectos.isEmpty())
this.trayectos.add(t);
else { protected void comprobarDatosContenedor(Trayecto t) {
Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1); Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1);
//Si la fecha fin es mayor a la de inicio del nuevo //Si la fecha fin es mayor a la de inicio del nuevo
if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch()) if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch())
throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente");
//Si el puerto destino no es el origen del nuevo //Si el puerto destino no es el origen del nuevo
if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto())) if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto()))
throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto"); throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto");
//Si el muelle de destino no es el de origen del nuevo //Si el muelle de destino no es el de origen del nuevo
if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador())) if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador()))
throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto"); throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto");
this.trayectos.add(t); this.trayectos.add(t);
}
} }
/** /**
* Metodo que devuelve si un contenedor tiene techo * Metodo que devuelve si un contenedor tiene techo
* @return si tiene techo (true) o si no lo tiene (false) * @return si tiene techo (true) o si no lo tiene (false)
......
...@@ -6,5 +6,19 @@ public class Estandar extends Contenedor { ...@@ -6,5 +6,19 @@ public class Estandar extends Contenedor {
pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);
} }
@Override
public void anyadirTrayecto(Trayecto t) {
if (t==null) {
throw new IllegalArgumentException("h");
}
if (this.trayectos.isEmpty()) {
this.anyadirTrayecto(t);
}
else {
comprobarDatosContenedor(t);
}
}
} }
...@@ -5,7 +5,29 @@ public class FlatRack extends Contenedor{ ...@@ -5,7 +5,29 @@ public class FlatRack extends Contenedor{
public FlatRack(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual, public FlatRack(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual,
pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);
// TODO Auto-generated constructor stub
} }
@Override
public void anyadirTrayecto(Trayecto t) {
if (t==null) {
throw new IllegalArgumentException("h");
}
if (t instanceof TCamion) {
throw new IllegalArgumentException("No");
}
if (t instanceof TPackCamionBarco) {
throw new IllegalArgumentException("No");
}
if (t instanceof TPackCamionTren) {
throw new IllegalArgumentException("No");
}
comprobarDatosContenedor(t);
}
} }
...@@ -5,7 +5,32 @@ public class Refrigerado extends Contenedor{ ...@@ -5,7 +5,32 @@ public class Refrigerado extends Contenedor{
public Refrigerado(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual, public Refrigerado(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual,
pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) { pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo); super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);
} }
} @Override
public void anyadirTrayecto(Trayecto t) {
if (t==null) {
throw new IllegalArgumentException("h");
}
if (t instanceof TTren) {
throw new IllegalArgumentException("No");
}
if (t instanceof TPackCamionBarco) {
throw new IllegalArgumentException("No");
}
if (t instanceof TPackCamionTren) {
throw new IllegalArgumentException("No");
}
comprobarDatosContenedor(t);
}
}
\ No newline at end of file
...@@ -21,7 +21,7 @@ public class ContenedorTest { ...@@ -21,7 +21,7 @@ public class ContenedorTest {
@Test @Test
public void testContenedor() { public void testContenedor() {
ISO6346 i1 = new ISO6346("ZRE", 'J', 56731); ISO6346 i1 = new ISO6346("ZRE", 'J', 56731);
Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true); Contenedor c1 = new Estandar(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true);
assertEquals("ZREJ0567310", c1.getCodigo()); assertEquals("ZREJ0567310", c1.getCodigo());
assertEquals(100.0f, c1.obtenerPesoKilos(), 0.001f); assertEquals(100.0f, c1.obtenerPesoKilos(), 0.001f);
assertEquals(400.0f, c1.cargaUtilContenedorKilos(), 0.001f); assertEquals(400.0f, c1.cargaUtilContenedorKilos(), 0.001f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment