Merge branch 'master' of https://github.com/HeshamTB/Hajj-simulation into master
This commit is contained in:
commit
2c6721c89a
@ -1,5 +1,3 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Accident {
|
public class Accident {
|
||||||
@ -17,7 +15,7 @@ public class Accident {
|
|||||||
Date startOfSimDate = new Date(15000000);
|
Date startOfSimDate = new Date(15000000);
|
||||||
//TODO: make a static final class with needed values
|
//TODO: make a static final class with needed values
|
||||||
if (date.before(startOfSimDate)){
|
if (date.before(startOfSimDate)){
|
||||||
throw new IllegalArgumentException("Date of ee364.hajj.transport.Accident before t zero");
|
throw new IllegalArgumentException("Date of Accident before t zero");
|
||||||
}
|
}
|
||||||
else this.date = date;
|
else this.date = date;
|
||||||
}
|
}
|
@ -1,5 +1,3 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public interface Breakable {
|
public interface Breakable {
|
34
src/Campaign.java
Normal file
34
src/Campaign.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
public class Campaign {
|
||||||
|
|
||||||
|
private int UID;
|
||||||
|
private int workers;
|
||||||
|
private int numberOfPeople;
|
||||||
|
private String district;
|
||||||
|
private String name;
|
||||||
|
private boolean local;
|
||||||
|
|
||||||
|
|
||||||
|
public Campaign(int numberOfPeople){
|
||||||
|
/*
|
||||||
|
Make an array of pilgrims based on number of people with
|
||||||
|
a set ration pilgrims:workers
|
||||||
|
Assume not local
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// public Campaign(Pilgrim[] pilgrims){
|
||||||
|
// /*
|
||||||
|
// Calculate number of workers based on number of pilgrims (pilgrims.length;)
|
||||||
|
// Assume not local
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
public int getNumberofCars(){
|
||||||
|
//Assume each car holds 4 workers
|
||||||
|
return (int)workers/4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfBusses(){
|
||||||
|
return 0;//TODO: calc buses?
|
||||||
|
}
|
||||||
|
}
|
3
src/CanBeGovtCar.java
Normal file
3
src/CanBeGovtCar.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public interface CanBeGovtCar {
|
||||||
|
int getGovtID();
|
||||||
|
}
|
3
src/CanFixAccident.java
Normal file
3
src/CanFixAccident.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public interface CanFixAccident {
|
||||||
|
//void attendToAccident(Accident accident);
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
package ee364.hajj;
|
|
||||||
|
|
||||||
public enum Gender {
|
public enum Gender {
|
||||||
MALE,
|
MALE,
|
||||||
FEMALE
|
FEMALE
|
@ -1,5 +1,3 @@
|
|||||||
package ee364.hajj;
|
|
||||||
|
|
||||||
public enum Priority {
|
public enum Priority {
|
||||||
HIGH,
|
HIGH,
|
||||||
MID,
|
MID,
|
@ -1,5 +1,3 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Sedan extends Vehicle implements Breakable {
|
public class Sedan extends Vehicle implements Breakable {
|
||||||
@ -7,16 +5,28 @@ public class Sedan extends Vehicle implements Breakable {
|
|||||||
private final int TIME_TO_FIX = 15; //in minutes
|
private final int TIME_TO_FIX = 15; //in minutes
|
||||||
private boolean broken;
|
private boolean broken;
|
||||||
private boolean accident;
|
private boolean accident;
|
||||||
|
private int capacity;
|
||||||
|
|
||||||
public Sedan(double vehicleSize, boolean govtCar){
|
public Sedan(double vehicleSize){
|
||||||
super(vehicleSize, govtCar, 4);
|
super(vehicleSize);
|
||||||
|
capacity = 4; //Should make this attr. in vehicle.
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBroken(){ return broken; }
|
public boolean isBroken(){ return broken; }
|
||||||
public boolean isInAccident(){ return accident; }
|
public boolean isInAccident(){ return accident; }
|
||||||
public void _break(Date time) { this.broken = true; } //TODO
|
|
||||||
public void collide(Breakable car, Date time) { this.accident = true; }//TODO //Maybe add time of accident and other breakable args
|
@Override
|
||||||
|
public void collide(Breakable car, Date time) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void _break(Date time) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public int getTimeToFix(){ return TIME_TO_FIX; }
|
public int getTimeToFix(){ return TIME_TO_FIX; }
|
||||||
|
public int getCapacity() { return capacity; }
|
||||||
|
|
||||||
|
|
||||||
public void fixed() { this.broken = false; this.accident = false; }
|
public void fixed() { this.broken = false; this.accident = false; }
|
29
src/TrafficPoliceCar.java
Normal file
29
src/TrafficPoliceCar.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
public class TrafficPoliceCar extends Vehicle implements CanBeGovtCar {
|
||||||
|
|
||||||
|
private final double ADDED_EFFICIENCY = 0.05; // 5%
|
||||||
|
private int govtID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
16
src/Vehicle.java
Normal file
16
src/Vehicle.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
public abstract class Vehicle {
|
||||||
|
|
||||||
|
private double vehicleSize;
|
||||||
|
|
||||||
|
public Vehicle(double vehicleSize){
|
||||||
|
setVehicleSize(vehicleSize);
|
||||||
|
}
|
||||||
|
public double getVehicleSize() {
|
||||||
|
return vehicleSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVehicleSize(double vehicleSize) {
|
||||||
|
if (vehicleSize <= 0) throw new IllegalArgumentException("Vehicle can not be negative in length!");
|
||||||
|
else this.vehicleSize = vehicleSize;
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
package ee364.hajj.group;
|
|
||||||
|
|
||||||
import ee364.hajj.Priority;
|
|
||||||
|
|
||||||
public class Campaign implements PermitedForHaj {
|
|
||||||
|
|
||||||
private int UID;
|
|
||||||
private int workers;
|
|
||||||
private int numberOfPeople;
|
|
||||||
private String district;
|
|
||||||
private String name;
|
|
||||||
private boolean local;
|
|
||||||
|
|
||||||
private Pilgrim[] pilgrims;
|
|
||||||
|
|
||||||
public Campaign(int numberOfPeople){
|
|
||||||
/*
|
|
||||||
Make an array of pilgrims based on number of people with
|
|
||||||
a set ration pilgrims:workers
|
|
||||||
Assume not local
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public Campaign(Pilgrim[] pilgrims){
|
|
||||||
/*
|
|
||||||
Calculate number of workers based on number of pilgrims (pilgrims.length;)
|
|
||||||
Assume not local
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public int hasUID() {
|
|
||||||
return UID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isLocal() {
|
|
||||||
return local;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberofCars(){
|
|
||||||
//Assume each car holds 4 workers
|
|
||||||
return (int)workers/4;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfBusses(){
|
|
||||||
int highPriorityPilgrims = 0;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package ee364.hajj.group;
|
|
||||||
|
|
||||||
public interface PermitedForHaj {
|
|
||||||
//public boolean has_UID();
|
|
||||||
public int hasUID();
|
|
||||||
public boolean isLocal();
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package ee364.hajj.group;
|
|
||||||
|
|
||||||
import ee364.hajj.Gender;
|
|
||||||
import ee364.hajj.Priority;
|
|
||||||
|
|
||||||
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--;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
public interface CanFixAccident {
|
|
||||||
//void attendToAccident(ee364.hajj.transport.Accident accident);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
public class TrafficPoliceCar extends Vehicle implements CanFixAccident {
|
|
||||||
|
|
||||||
public final double ADDED_EFFICIENCY = 0.05; // 5%
|
|
||||||
//private Street str_location or name
|
|
||||||
private static int totalTrafficCars;
|
|
||||||
|
|
||||||
public TrafficPoliceCar(double vehicleSize, boolean govtCar){
|
|
||||||
super(vehicleSize, govtCar, 2); //Capacity is irrelevant.
|
|
||||||
totalTrafficCars++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTotalTrafficCars() {
|
|
||||||
return totalTrafficCars;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
super.finalize();
|
|
||||||
totalTrafficCars--;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package ee364.hajj.transport;
|
|
||||||
|
|
||||||
public abstract class Vehicle {
|
|
||||||
|
|
||||||
private double vehicleSize;
|
|
||||||
private boolean govtCar;
|
|
||||||
private int capacity;
|
|
||||||
|
|
||||||
public Vehicle(double vehicleSize, boolean govtCar, int capacity){
|
|
||||||
this.vehicleSize = vehicleSize;
|
|
||||||
this.govtCar = govtCar;
|
|
||||||
setCapacity(capacity);
|
|
||||||
}
|
|
||||||
public double getVehicleSize() {
|
|
||||||
return vehicleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGovtCar() {
|
|
||||||
return govtCar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCapacity() {
|
|
||||||
return capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setCapacity(int capacity) throws IllegalArgumentException {
|
|
||||||
if (capacity > 0 && capacity < 50){
|
|
||||||
this.capacity = capacity;
|
|
||||||
}
|
|
||||||
else throw new IllegalArgumentException(String.format("Invalid vehicle capacity %d", capacity));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user