Added Vehicle data structure

This commit is contained in:
HeshamTB 2020-10-09 22:58:00 +03:00
parent 50fcd50693
commit 3dbb440370
Signed by: Hesham
GPG Key ID: 74876157D199B09E
4 changed files with 56 additions and 0 deletions

7
src/Breakable.java Normal file
View File

@ -0,0 +1,7 @@
public interface Breakable {
public int getTimeToFix();
public boolean isBroken();
public boolean isInAccident();
}

23
src/Sedan.java Normal file
View File

@ -0,0 +1,23 @@
public class Sedan extends Vehicle implements Breakable {
private final int TIME_TO_FIX = 15; //in minutes
private boolean broken;
private boolean accident;
private int capacity;
public Sedan(double vehicleSize, boolean govtCar){
super(vehicleSize, govtCar);
capacity = 4; //Should make this attr. in vehicle.
}
public boolean isBroken(){ return broken; }
public boolean isInAccident(){ return accident; }
public int getTimeToFix(){ return TIME_TO_FIX; }
public int getCapacity() { return capacity; }
public void collide() { this.accident = true; }
public void _break() { this.broken = true; }
public void fixed() { this.broken = false; this.accident = false; }
}

View File

@ -0,0 +1,9 @@
public class TrafficPoliceCar extends Vehicle {
private final double ADDED_EFFICIENCY = 0.05; // 5%
public TrafficPoliceCar(double vehicleSize, boolean govtCar){
super(vehicleSize, govtCar);
}
}

17
src/Vehicle.java Normal file
View File

@ -0,0 +1,17 @@
public abstract class Vehicle {
private double vehicleSize;
private boolean govtCar;
public Vehicle(double vehicleSize, boolean govtCar){
this.vehicleSize = vehicleSize;
this.govtCar = govtCar;
}
public double getVehicleSize() {
return vehicleSize;
}
public boolean isGovtCar() {
return govtCar;
}
}