Restructure of Oct 18th meeting

some of the changes proposed in 18-10-2020 meeting:

- GovtCar marker interface (CanBeGovtCar)
- Remove isGovt from vehicle and Sedan constructors
- Remove Pilgrim.java class
- Remove PermitedForHaj.java interface
This commit is contained in:
HeshamTB 2020-10-20 02:33:57 +03:00
parent 58dfb37437
commit 16ce4857c8
7 changed files with 41 additions and 81 deletions

View File

@ -1,4 +1,4 @@
public class Campaign implements PermitedForHaj { public class Campaign {
private int UID; private int UID;
private int workers; private int workers;
@ -7,7 +7,6 @@ public class Campaign implements PermitedForHaj {
private String name; private String name;
private boolean local; private boolean local;
private Pilgrim[] pilgrims;
public Campaign(int numberOfPeople){ public Campaign(int numberOfPeople){
/* /*
@ -17,21 +16,12 @@ public class Campaign implements PermitedForHaj {
*/ */
} }
public Campaign(Pilgrim[] pilgrims){ // public Campaign(Pilgrim[] pilgrims){
/* // /*
Calculate number of workers based on number of pilgrims (pilgrims.length;) // Calculate number of workers based on number of pilgrims (pilgrims.length;)
Assume not local // Assume not local
*/ // */
} // }
@Override
public int hasUID() {
return UID;
}
@Override
public boolean isLocal() {
return local;
}
public int getNumberofCars(){ public int getNumberofCars(){
//Assume each car holds 4 workers //Assume each car holds 4 workers
@ -39,13 +29,6 @@ public class Campaign implements PermitedForHaj {
} }
public int getNumberOfBusses(){ public int getNumberOfBusses(){
int highPriorityPilgrims = 0; return 0;//TODO: calc buses?
int totalBusses = 0;
for (Pilgrim pilgrim : pilgrims){
if (pilgrim.getPriority() == Priority.HIGH) highPriorityPilgrims++;
}
totalBusses += highPriorityPilgrims/20; //Assume pilgims with physical disability
totalBusses += (pilgrims.length - highPriorityPilgrims)/40; //Remaining pilgrims fill busses
return totalBusses;
} }
} }

3
src/CanBeGovtCar.java Normal file
View File

@ -0,0 +1,3 @@
public interface CanBeGovtCar {
int getGovtID();
}

View File

@ -1,5 +0,0 @@
public interface PermitedForHaj {
//public boolean has_UID();
public int hasUID();
public boolean isLocal();
}

View File

@ -1,40 +0,0 @@
public class Pilgrim {
//keep track of all pilgrim object count.
private static int totalPilgrims;
private String passport;
private boolean local;
private int age;
private Gender gender;
private Priority priority;
public Pilgrim(String passport, int age, Gender gender, Priority priority, boolean local) throws Exception {
setAge(age);
setPassport(passport);
this.gender = gender;
this.priority = priority;
totalPilgrims++; //Added a pilgrim
}
public Priority getPriority() { return priority; }
private void setAge(int age) throws IllegalArgumentException {
if (age < 7 || age > 85) throw new IllegalArgumentException("Age out of permitted range");
else this.age = age;
}
private void setPassport(String passport) throws IllegalArgumentException{
if (passport.length() == 8) //assuming standard passport number lengths
this.passport = passport;
else throw new IllegalArgumentException("Invalid passport format");
//TODO:Make exception classes
}
@Override
protected void finalize() throws Throwable {
super.finalize();
//Decrement the count of total objects when GC cleans unneeded.
totalPilgrims--;
}
}

View File

@ -5,8 +5,8 @@ public class Sedan extends Vehicle implements Breakable {
private boolean accident; private boolean accident;
private int capacity; private int capacity;
public Sedan(double vehicleSize, boolean govtCar){ public Sedan(double vehicleSize){
super(vehicleSize, govtCar); super(vehicleSize);
capacity = 4; //Should make this attr. in vehicle. capacity = 4; //Should make this attr. in vehicle.
} }

View File

@ -1,9 +1,29 @@
public class TrafficPoliceCar extends Vehicle { public class TrafficPoliceCar extends Vehicle implements CanBeGovtCar {
private final double ADDED_EFFICIENCY = 0.05; // 5% private final double ADDED_EFFICIENCY = 0.05; // 5%
private int govtID;
public TrafficPoliceCar(double vehicleSize, boolean govtCar){ /**
super(vehicleSize, govtCar); * construct instance with random GovtID
* @param vehicleSize Length of vehicle in meters
*/
public TrafficPoliceCar(double vehicleSize){
super(vehicleSize);
//TODO: Set random govtID
} }
/**
* Construct instance with given GovtID
* @param vehicleSize Length of vehicle in meters
* @param govtID Provided Govt ID
*/
public TrafficPoliceCar(double vehicleSize, int govtID) {
super(vehicleSize);
this.govtID = govtID;
}
@Override
public int getGovtID() {
return govtID;
}
} }

View File

@ -1,17 +1,16 @@
public abstract class Vehicle { public abstract class Vehicle {
private double vehicleSize; private double vehicleSize;
private boolean govtCar;
public Vehicle(double vehicleSize, boolean govtCar){ public Vehicle(double vehicleSize){
this.vehicleSize = vehicleSize; setVehicleSize(vehicleSize);
this.govtCar = govtCar;
} }
public double getVehicleSize() { public double getVehicleSize() {
return vehicleSize; return vehicleSize;
} }
public boolean isGovtCar() { public void setVehicleSize(double vehicleSize) {
return govtCar; if (vehicleSize <= 0) throw new IllegalArgumentException("Vehicle can not be negative in length!");
else this.vehicleSize = vehicleSize;
} }
} }