From 50fcd506938ddff31130d57c23b0e5eb1104fb1b Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 9 Oct 2020 22:22:37 +0300 Subject: [PATCH] init commit - Campaign, Pilgrim and enums - Project files --- .idea/.gitignore | 3 +++ .idea/misc.xml | 6 +++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ Hajj-simulation.iml | 11 +++++++++ src/Campaign.java | 51 +++++++++++++++++++++++++++++++++++++++++ src/Gender.java | 4 ++++ src/PermitedForHaj.java | 5 ++++ src/Pilgrim.java | 31 +++++++++++++++++++++++++ src/Priority.java | 5 ++++ 10 files changed, 130 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Hajj-simulation.iml create mode 100644 src/Campaign.java create mode 100644 src/Gender.java create mode 100644 src/PermitedForHaj.java create mode 100644 src/Pilgrim.java create mode 100644 src/Priority.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..34e9dc7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Hajj-simulation.iml b/Hajj-simulation.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Hajj-simulation.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Campaign.java b/src/Campaign.java new file mode 100644 index 0000000..fa2fc86 --- /dev/null +++ b/src/Campaign.java @@ -0,0 +1,51 @@ +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; + } +} diff --git a/src/Gender.java b/src/Gender.java new file mode 100644 index 0000000..90fb7b3 --- /dev/null +++ b/src/Gender.java @@ -0,0 +1,4 @@ +public enum Gender { + MALE, + FEMALE +} diff --git a/src/PermitedForHaj.java b/src/PermitedForHaj.java new file mode 100644 index 0000000..ac552f2 --- /dev/null +++ b/src/PermitedForHaj.java @@ -0,0 +1,5 @@ +public interface PermitedForHaj { + //public boolean has_UID(); + public int hasUID(); + public boolean isLocal(); +} diff --git a/src/Pilgrim.java b/src/Pilgrim.java new file mode 100644 index 0000000..26c4411 --- /dev/null +++ b/src/Pilgrim.java @@ -0,0 +1,31 @@ +public class Pilgrim { + + 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; + } + public Priority getPriority() { + return priority; + } + + private void setAge(int age) throws Exception { + if (age < 7 || age > 85) throw new Exception("Age out of permitted range"); + else this.age = age; + } + + private void setPassport(String passport) throws Exception { + if (passport.length() == 8) //assuming standard passport number lengths + this.passport = passport; + else throw new Exception("Invalid passport format"); + //TODO:Make exception classes + } +} diff --git a/src/Priority.java b/src/Priority.java new file mode 100644 index 0000000..6fa254a --- /dev/null +++ b/src/Priority.java @@ -0,0 +1,5 @@ +public enum Priority { + HIGH, + MID, + LOW +}