Added classes:
- Bus class that extends Vehicle and implements Breakable - Street class and properties - Route still to be updated. Add Locations for start/end?
This commit is contained in:
parent
c5db5dcac0
commit
e12c5ec296
46
src/Bus.java
Normal file
46
src/Bus.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.util.Date;
|
||||
|
||||
public class Bus extends Vehicle implements Breakable {
|
||||
|
||||
private final int TIME_TO_FIX = 20; //in minutes
|
||||
private boolean broken;
|
||||
private boolean inAccident;
|
||||
private Date breakDownTime;//TODO: PDate
|
||||
|
||||
public Bus(double vehicleSize) {
|
||||
super(vehicleSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeToFix() {
|
||||
return TIME_TO_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBroken() {
|
||||
return broken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInAccident() {
|
||||
return inAccident;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(Breakable car, Date time) {
|
||||
//Make Accident here and change return type?
|
||||
// or make reference as property
|
||||
}
|
||||
|
||||
@Override
|
||||
public void _break(Date time) {
|
||||
broken = true;
|
||||
breakDownTime = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fix() {
|
||||
broken = false;
|
||||
inAccident = false;
|
||||
}
|
||||
}
|
21
src/Route.java
Normal file
21
src/Route.java
Normal file
@ -0,0 +1,21 @@
|
||||
public class Route {
|
||||
|
||||
private Street[] streets;
|
||||
|
||||
public Route(Street[] streets) {
|
||||
this.streets = streets;
|
||||
}
|
||||
|
||||
public Street[] getStreets() {
|
||||
return this.streets;
|
||||
}
|
||||
|
||||
public double getTotalLength() {
|
||||
double totalLength = 0;
|
||||
for (Street st : streets){
|
||||
totalLength += st.getLength();
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
}
|
40
src/Street.java
Normal file
40
src/Street.java
Normal file
@ -0,0 +1,40 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Street {
|
||||
|
||||
private double length;
|
||||
private int numberOfLanes;
|
||||
private ArrayList<Vehicle> vehicles;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user