2020-10-21 02:15:03 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class Street {
|
|
|
|
|
|
|
|
private double length;
|
|
|
|
private int numberOfLanes;
|
|
|
|
private ArrayList<Vehicle> vehicles;
|
2020-11-08 14:03:44 +01:00
|
|
|
|
2020-10-21 02:15:03 +02:00
|
|
|
|
|
|
|
public Street(double length, int numberOfLanes) {
|
|
|
|
setLength(length);
|
|
|
|
setNumberOfLanes(numberOfLanes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Street(double length, int numberOfLanes, ArrayList<Vehicle> vehicles) {
|
|
|
|
this(length, numberOfLanes);
|
|
|
|
this.vehicles = vehicles;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setLength(double length) {
|
|
|
|
if (length >= 0) this.length = length;
|
|
|
|
else throw new IllegalArgumentException("Can not make a negative length street");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setNumberOfLanes(int numberOfLanes) {
|
|
|
|
if (numberOfLanes >= 1) this.numberOfLanes = numberOfLanes;
|
|
|
|
else throw new IllegalArgumentException("Street can not have less then 1 lane");
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getLength() {
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNumberOfLanes() {
|
|
|
|
return numberOfLanes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<Vehicle> getVehicles() {
|
|
|
|
return vehicles;
|
|
|
|
}
|
2020-11-09 10:24:51 +01:00
|
|
|
|
2020-11-08 14:03:44 +01:00
|
|
|
public double capcity() {
|
2020-11-09 10:24:51 +01:00
|
|
|
double totalLength = length * numberOfLanes;
|
|
|
|
//TODO Ammar return (total length - (length of cars + padding))
|
|
|
|
double totalLenthofCar=0;
|
|
|
|
for(int i=0;i<vehicles.size();i++) {
|
|
|
|
totalLenthofCar+=vehicles.get(i).getVehicleSize();
|
|
|
|
}
|
2020-11-09 10:42:32 +01:00
|
|
|
return totalLength -(totalLenthofCar + 0.5*(vehicles.size() - 2));
|
2020-11-08 14:03:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canTakeVehicles( Vehicle vehicle ) {
|
|
|
|
if ( vehicle.getVehicleSize() > capcity() )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-09 10:24:51 +01:00
|
|
|
|
2020-11-09 10:30:18 +01:00
|
|
|
public void addVehicle(Vehicle vehicle) {
|
|
|
|
if(capcity() > 0) {
|
|
|
|
//adds incoming vehicle in last.
|
|
|
|
vehicles.add(vehicle);
|
2020-11-09 10:24:51 +01:00
|
|
|
}
|
|
|
|
//TODO Ammar i hope that
|
2020-11-08 14:03:44 +01:00
|
|
|
}
|
2020-11-08 14:34:10 +01:00
|
|
|
|
2020-10-21 02:15:03 +02:00
|
|
|
}
|