modif : isValid, getLength, getTravelTime, getMinimumTravelTime

This commit is contained in:
Norgeux Lea 2023-03-22 10:34:25 +01:00
parent 1ebdc88d8c
commit 9a8c602289

View file

@ -201,8 +201,30 @@ public class Path {
* @deprecated Need to be implemented.
*/
public boolean isValid() {
// TODO:
return false;
if (this.isEmpty() == true) {
return true ;
}
if (this.size() == 1) {
return true ;
}
int i = 0 ;
if (!this.getArcs().get(i).getOrigin().equals(this.origin)) {
return false ;
}
for (i=1;i<this.getArcs().size();i++) {
if (!this.getArcs().get(i-1).getDestination().equals(this.getArcs().get(i).getOrigin())) {
return false ;
}
}
return true ;
}
/**
@ -210,11 +232,14 @@ public class Path {
*
* @return Total length of the path (in meters).
*
* @deprecated Need to be implemented.
*
*/
public float getLength() {
// TODO:
return 0;
float result = 0.0f ;
for (Arc a : this.getArcs()) {
result += a.getLength() ;
}
return result;
}
/**
@ -225,11 +250,10 @@ public class Path {
* @return Time (in seconds) required to travel this path at the given speed (in
* kilometers-per-hour).
*
* @deprecated Need to be implemented.
*
*/
public double getTravelTime(double speed) {
// TODO:
return 0;
return (this.getLength()/speed)*3.6f;
}
/**
@ -238,11 +262,14 @@ public class Path {
*
* @return Minimum travel time to travel this path (in seconds).
*
* @deprecated Need to be implemented.
*
*/
public double getMinimumTravelTime() {
// TODO:
return 0;
double result = 0.0 ;
for (Arc a : this.getArcs()) {
result += a.getMinimumTravelTime() ;
}
return result ;
}
}