Added Vehicle data structure
This commit is contained in:
parent
50fcd50693
commit
3dbb440370
7
src/Breakable.java
Normal file
7
src/Breakable.java
Normal file
@ -0,0 +1,7 @@
|
||||
public interface Breakable {
|
||||
|
||||
public int getTimeToFix();
|
||||
public boolean isBroken();
|
||||
public boolean isInAccident();
|
||||
|
||||
}
|
23
src/Sedan.java
Normal file
23
src/Sedan.java
Normal 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; }
|
||||
|
||||
}
|
9
src/TrafficPoliceCar.java
Normal file
9
src/TrafficPoliceCar.java
Normal 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
17
src/Vehicle.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user