Skip to content
Snippets Groups Projects
Commit 8f862ad1 authored by Javier Calvo's avatar Javier Calvo
Browse files

Trayectos acabado

parent 8cdd2685
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ package es.markse;
* @author javcalv
* @author victorm
*/
public class TBarco extends TrayectoSimple {
public class TBarco extends TSimple {
private final double COSTE_DIARIO = 4000;
......@@ -26,10 +26,11 @@ public class TBarco extends TrayectoSimple {
public TBarco(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
//Comprobamos si el Muelle origen/destino esta alejado del barco
if(muelleOrigen.alejadoBarco())
throw new IllegalStateException("El Muelle de origen esta alejado del barco (No puede usar ese transporte)");
throw new IllegalStateException("El Muelle de origen esta alejado del barco (No puede usar este transporte)");
if(muelleDestino.alejadoBarco())
throw new IllegalStateException("El Muelle de destino esta alejado del barco");
throw new IllegalStateException("El Muelle de destino esta alejado del barco (No puede usar ese transporte)");
}
/**
......
......
......@@ -8,10 +8,10 @@ package es.markse;
* @author javcalv
* @author victorm
*/
public class TCamion extends TrayectoSimple {
public class TCamion extends TVehiculoTierra {
private double COSTE_FIJO = 200;
private double COSTE_POR_KILOMETRO = 4.5;
private final double COSTE = 200;
private final double COSTE_KILOMETRO = 4.5;
/**
* Constructor de la clase TCamion
......@@ -24,36 +24,9 @@ public class TCamion extends TrayectoSimple {
*/
public TCamion(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
}
/**
* Método que calcula el coste del trayecto por camión
* @return Coste del trayecto en euros
*/
@Override
public double costeTrayecto() {
return COSTE_FIJO + (this.distanciaKilometros * COSTE_POR_KILOMETRO);
}
/**
* Metodo para cambiar el coste fijo de un trayecto
* @param coste coste fijo nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
public void cambiarCosteFijo(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_FIJO = coste;
}
/**
* Metodo para cambiar el coste por kilometro de un trayecto
* @param coste coste por kilometro nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
public void cambiarCostePorKilometro(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_POR_KILOMETRO = coste;
//Inicializamos el valor para el Camion
this.COSTE_FIJO = this.COSTE;
this.COSTE_POR_KILOMETRO = this.COSTE_KILOMETRO;
}
}
\ No newline at end of file
......@@ -9,10 +9,10 @@ import java.util.ArrayList;
* @author javcalv
* @author victorm
*/
public abstract class TrayectoCombinado extends Trayecto {
public abstract class TCombinado extends Trayecto {
//ArrayList para guardar todos los trayectos simples
protected ArrayList<TrayectoSimple> trayectosSimples;
protected ArrayList<TSimple> trayectosSimples;
/**
* Constructor de la clase abstracta TrayectoCombinado
......@@ -23,7 +23,7 @@ public abstract class TrayectoCombinado extends Trayecto {
* @param puertoDestino Puerto en el que finaliza un Trayecto
* @param fechaFinTrayecto Fecha en la que finaliza un Trayecto
*/
public TrayectoCombinado(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
public TCombinado(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
this.trayectosSimples = new ArrayList<>();
}
......@@ -31,7 +31,7 @@ public abstract class TrayectoCombinado extends Trayecto {
/*********************************************************
* METODOS EJECUTADOS POR EL COSTRUCTOR DE LAS SUBCLASES *
*********************************************************/
protected boolean estanVacios(ArrayList<TrayectoSimple> ts) {
protected boolean estanVacios(ArrayList<TSimple> ts) {
return (ts.isEmpty() || ts == null) ? true : false;
}
......@@ -40,9 +40,9 @@ public abstract class TrayectoCombinado extends Trayecto {
* @param trayectos ArrayList de los trayectos simples a comprobar
* @return true si hay trayectos de camion o false si no los hay
*/
protected boolean comprobarSiHayTrayectosCamion(ArrayList<TrayectoSimple> ts) {
protected boolean comprobarSiHayTrayectosCamion(ArrayList<TSimple> ts) {
int trayectosCamiones = 0;
for (TrayectoSimple t : ts) {
for (TSimple t : ts) {
if (t instanceof TCamion) trayectosCamiones++;
}
return (trayectosCamiones == 0)? false : true;
......@@ -52,12 +52,13 @@ public abstract class TrayectoCombinado extends Trayecto {
* Metodo que comprueba si el arraylist tiene un orden correcto:
* - El destino del muelle/puerto es el origen del trayecto siguiente
* @param ts ArrayList de los trayectos
* @return true si es un orden corr
* @return true si es un orden correcto o false si no lo es
* @throws IllegalArgumentException Si hay elementos vacios de poer medio
*/
protected boolean ordenTrayectosCorrecto(ArrayList<TrayectoSimple> ts) {
protected boolean ordenTrayectosCorrecto(ArrayList<TSimple> ts) {
for (int i = 0; i<(ts.size() - 1); i++) {
TrayectoSimple t1 = ts.get(i);
TrayectoSimple t2 = ts.get(i + 1);
TSimple t1 = ts.get(i);
TSimple t2 = ts.get(i + 1);
if (t1 == null || t2 == null) {
throw new IllegalArgumentException("Hay trayectos nulos en la lista");
}
......@@ -73,7 +74,7 @@ public abstract class TrayectoCombinado extends Trayecto {
* @param t2 trayecto compuesto posterior
* @return true si el destino y el origen de siguiente son iguales o false si no lo son
*/
private boolean comprobarDestinoOrigenIguales(TrayectoSimple t1, TrayectoSimple t2) {
private boolean comprobarDestinoOrigenIguales(TSimple t1, TSimple t2) {
return (t1.getMuelleDestino().getIdentificador().equals(t2.getMuelleOrigen().getIdentificador()) &&
t1.getPuertoDestino().identificadorPuerto().equals(t2.getPuertoOrigen().identificadorPuerto()))
? true : false;
......
......
......@@ -10,10 +10,7 @@ import java.util.ArrayList;
* @author javcalv
* @author victorm
*/
public class TPackCamionBarco extends TrayectoCombinado {
private final ArrayList<TCamion> trayectosCamion;
private final ArrayList<TBarco> trayectosBarco;
public class TPackCamionBarco extends TCombinado {
//Descuentos que se aplican
private final double DESCUENTO = 0.85;
......@@ -30,19 +27,63 @@ public class TPackCamionBarco extends TrayectoCombinado {
* @param trayectosBarco
*/
public TPackCamionBarco(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino,
Puerto puertoDestino, Fecha fechaFinTrayecto, ArrayList<TCamion> trayectosCamion, ArrayList<TBarco> trayectosBarco) {
Puerto puertoDestino, Fecha fechaFinTrayecto, ArrayList<TSimple> trayectosSimples) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
//Comprobamos si los trayectos no estan nulos (Debe de tener uno al menos)
if(trayectosCamion == null)
if(estanVacios(trayectosSimples))
throw new IllegalArgumentException("Los trayectos en camion estan vacios");
if(trayectosBarco == null)
throw new IllegalArgumentException("Los trayectos en barco estan nulos");
this.trayectosCamion = trayectosCamion;
this.trayectosBarco = trayectosBarco;
//Comprobamos si las clases son solo de tipo Camion o Tren
if (trayectosCorrectos(trayectosSimples))
throw new IllegalArgumentException("Las clases agregadas al ArrayList son invalidas");
//Comprobar si hay un trayecto de barco y de camion al menos (Obligatorio por nuestra parte)
if (!this.comprobarSiHayTrayectosCamion(trayectosSimples))
throw new IllegalArgumentException("En los trayectos no hay trayectos en camion (Es obligatorio)");
if (!this.comprobarSiHayTrayectosBarco(trayectosSimples))
throw new IllegalArgumentException("En los trayectos no hay trayectos en tren (Es obligatorio)");
//Comprobamos que el orden de los trayectos sea correcto (Destino de uno es el origen del siguiente)
if (!this.ordenTrayectosCorrecto(trayectosSimples))
throw new IllegalArgumentException("El orden de los trayectos no es correcto. "
+ "Comprueba si el destino es el mismo que el origen del siguiente trayecto");
this.trayectosSimples = trayectosSimples;
}
/**
* Metodo para comparar si las instancias de los trayectos simples son correctas
* @param ts Arraylist con los Trayectos a comparar
* @return true si son correctos o false si no lo son
*/
private boolean trayectosCorrectos(ArrayList<TSimple> ts) {
for (TSimple t : ts) {
if (!(t instanceof TCamion || t instanceof TBarco)) {
return false;
}
}
return true;
}
/**
* Metodo que comprueba si hay trayectos de barco en el pack
* @param trayectos ArrayList de los trayectos simples a comprobar
* @return true si hay trayectos de tren o false si no los hay
*/
private boolean comprobarSiHayTrayectosBarco(ArrayList<TSimple> trayectos) {
int trayectosBarco = 0;
for (TSimple t : trayectos) {
if (t instanceof TBarco) trayectosBarco++;
}
return (trayectosBarco == 0)? false : true;
}
/************************
* METODOS DEL TRAYECTO *
************************/
/**
* Método que calcula el coste del trayecto combinado de camión y barco
* @return Coste del trayecto en euros
......@@ -50,11 +91,15 @@ public class TPackCamionBarco extends TrayectoCombinado {
@Override
public double costeTrayecto() {
double coste = 0;
for (TCamion camion : this.trayectosCamion) {
coste += camion.costeTrayecto();
for (TSimple ts: this.trayectosSimples) {
if (ts instanceof TBarco) {
TBarco tb = (TBarco) ts;
coste += tb.costeTrayecto() * this.DESCUENTO;
}
else {
TCamion tc = (TCamion) ts;
coste += tc.costeTrayecto();
}
for (TBarco barco : this.trayectosBarco) {
coste += barco.costeTrayecto() * this.DESCUENTO;
}
return coste;
}
......
......
......@@ -9,11 +9,11 @@ import java.util.ArrayList;
* @author javcalv
* @author victorm
*/
public class TPackCamionTren extends TrayectoCombinado {
public class TPackCamionTren extends TCombinado {
//Nuevas ofertas para este pack
private final int COSTE_FIJO = 0;
private final int COSTE_POR_KILOMETRO = 10;
//Reduccion de los precios
private final int RED_COSTE_FIJO = 0;
private final int RED_COSTE_POR_KILOMETRO = 10;
/**
* Constructor de la clase PackCamionTren
......@@ -24,15 +24,24 @@ public class TPackCamionTren extends TrayectoCombinado {
* @param puertoDestino Puerto en el que finaliza un Trayecto
* @param fechaFinTrayecto Fecha en la que finaliza un Trayecto
* @param trayectosSimples ArrayList con los trayectos simples
* @throws IllegalArgumentException Si la lista esta vacia
* @throws IllegalArgumentException Si las clases agregadas en el ArrayList son invalidas
* @throws IllegalArgumentException Si no se encuentra un solo trayecto de camion en la lista
* @throws IllegalArgumentException Si no se encuentra un solo trayecto de tren en la lista
* @throws IllegalArgumentException Si El orden de los trayectos no es correcto
*/
public TPackCamionTren(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino,
Puerto puertoDestino, Fecha fechaFinTrayecto, ArrayList<TrayectoSimple> trayectosSimples) {
Puerto puertoDestino, Fecha fechaFinTrayecto, ArrayList<TSimple> trayectosSimples){
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
//Comprobamos que los trayectos no sean nulos/vacios
if (estanVacios(trayectosSimples))
throw new IllegalArgumentException("Los trayectos no pueden ser nulos/vacios");
//Comprobamos si las clases son solo de tipo Camion o Tren
if (trayectosCorrectos(trayectosSimples))
throw new IllegalArgumentException("Las clases agregadas al ArrayList son invalidas");
//Comprobar si hay un trayecto de barco y de camion al menos (Obligatorio por nuestra parte)
if (!this.comprobarSiHayTrayectosCamion(trayectosSimples))
throw new IllegalArgumentException("En los trayectos no hay trayectos en camion (Es obligatorio)");
......@@ -52,14 +61,28 @@ public class TPackCamionTren extends TrayectoCombinado {
* @param trayectos ArrayList de los trayectos simples a comprobar
* @return true si hay trayectos de tren o false si no los hay
*/
private boolean comprobarSiHayTrayectosTren(ArrayList<TrayectoSimple> trayectos) {
private boolean comprobarSiHayTrayectosTren(ArrayList<TSimple> trayectos) {
int trayectosTren = 0;
for (TrayectoSimple t : trayectos) {
for (TSimple t : trayectos) {
if (t instanceof TTren) trayectosTren++;
}
return (trayectosTren == 0)? false : true;
}
/**
* Metodo para comparar si las instancias de los trayectos simples son correctas
* @param ts Arraylist con los Trayectos a comparar
* @return true si son correctos o false si no lo son
*/
private boolean trayectosCorrectos(ArrayList<TSimple> ts) {
for (TSimple t : ts) {
if (!(t instanceof TCamion || t instanceof TTren)) {
return false;
}
}
return true;
}
/************************
* METODOS DEL TRAYECTO *
......@@ -70,11 +93,15 @@ public class TPackCamionTren extends TrayectoCombinado {
* @return Coste del trayecto en euros
*/
@Override
//CAMBIAR --> CREAR SUBCLASE?? Y CREAR AHI LOS METODOS?? o PONERLOS EN EL SIMPLE Y HERENCIA
public double costeTrayecto() {
for (TrayectoSimple ts : this.trayectosSimples) {
ts.
double coste = 0;
for (TSimple ts : this.trayectosSimples) {
//Sabemos que obligaotoriamente es de tipo TVehiculoTierra
TVehiculoTierra tv = (TVehiculoTierra) ts;
tv.COSTE_FIJO = this.RED_COSTE_FIJO;
tv.COSTE_POR_KILOMETRO = this.RED_COSTE_POR_KILOMETRO;
coste += tv.costeTrayecto();
}
return coste;
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ package es.markse;
* @author javcalv
* @author victorm
*/
public abstract class TrayectoSimple extends Trayecto {
public abstract class TSimple extends Trayecto {
protected double distanciaKilometros;
private final float MILLAS_A_KILOMETROS = 1.852f;
......@@ -22,7 +22,7 @@ public abstract class TrayectoSimple extends Trayecto {
* @param puertoDestino Puerto en el que finaliza un Trayecto
* @param fechaFinTrayecto Fecha en la que finaliza un Trayecto
*/
public TrayectoSimple(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
public TSimple(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
//Obtenemos la distancia en millas marinas del trayecto y las convertimos en kilometros
......
......
......@@ -8,10 +8,10 @@ package es.markse;
* @author javcalv
* @author victorm
*/
public class TTren extends TrayectoSimple {
public class TTren extends TVehiculoTierra{
private double COSTE_FIJO = 20;
private double COSTE_POR_KILOMETRO = 12.5;
private double COSTE = 20;
private double COSTE_KILOMETRO = 12.5;
/**
* Constructor de la clase TTren
......@@ -32,38 +32,9 @@ public class TTren extends TrayectoSimple {
throw new IllegalStateException("El muelle de origen no puede usar el transporte Tren");
if(!muelleDestino.utilidadTren())
throw new IllegalStateException("El muelle destino no puede usar el transporte Tren");
}
/**
* Método que calcula el coste del trayecto por tren
* @return Coste del trayecto en euros
*/
@Override
public double costeTrayecto() {
return COSTE_FIJO + (this.distanciaKilometros * COSTE_POR_KILOMETRO);
}
/**
* Metodo para cambiar el coste fijo de un trayecto
* @param coste coste fijo nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
protected void cambiarCosteFijo(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_FIJO = coste;
}
/**
* Metodo para cambiar el coste por kilometro de un trayecto
* @param coste coste por kilometro nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
protected void cambiarCostePorKilometro(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_POR_KILOMETRO = coste;
//Inicializamos los valores para el trayecto Tren
this.COSTE_FIJO = COSTE;
this.COSTE_POR_KILOMETRO = this.COSTE_KILOMETRO;
}
}
\ No newline at end of file
package es.markse;
public abstract class TVehiculoTierra extends TSimple{
protected double COSTE_FIJO;
protected double COSTE_POR_KILOMETRO;
public TVehiculoTierra(Muelle muelleOrigen, Puerto puertoOrigen, Fecha fechaInicioTrayecto, Muelle muelleDestino, Puerto puertoDestino, Fecha fechaFinTrayecto) {
super(muelleOrigen, puertoOrigen, fechaInicioTrayecto, muelleDestino, puertoDestino, fechaFinTrayecto);
}
/**************************************************
* METODOS QUE SE APLICARAN A VEHICULOS DE TIERRA *
**************************************************/
/**
* Método que calcula el coste del trayecto por camión
* @return Coste del trayecto en euros
*/
@Override
public double costeTrayecto() {
return COSTE_FIJO + (this.distanciaKilometros * COSTE_POR_KILOMETRO);
}
/**
* Metodo para cambiar el coste fijo de un trayecto
* @param coste coste fijo nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
protected void cambiarCosteFijo(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_FIJO = coste;
}
/**
* Metodo para cambiar el coste por kilometro de un trayecto
* @param coste coste por kilometro nuevo
* @throws IllegalArgumentException el coste no puede ser negativo
*/
protected void cambiarCostePorKilometro(double coste) {
if(coste<0)
throw new IllegalArgumentException("Coste no puede ser negativo");
this.COSTE_POR_KILOMETRO = coste;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment