Commit bd5d87b
Changed files (4)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
test
java
ca
mokhan
assignment1
assignments/assignment1/src/main/java/ca/mokhan/assignment1/Candidate.java
@@ -4,7 +4,7 @@ import java.util.ArrayList;
public class Candidate extends AddressBook {
private double grade = 0.0;
- private String communication;
+ private Communication communication;
private boolean isInnovative;
private double regulatoryCapability;
@@ -17,7 +17,7 @@ public class Candidate extends AddressBook {
double regulatoryCapability) {
super(firstName, "", lastName);
this.grade = grade;
- this.communication = communication;
+ this.setCommunication(communication);
this.isInnovative = isInnovative;
this.regulatoryCapability = regulatoryCapability;
}
@@ -35,11 +35,11 @@ public class Candidate extends AddressBook {
}
public String getCommunication() {
- return this.communication;
+ return this.communication.toString();
}
public void setCommunication(String communication) {
- this.communication = communication;
+ this.communication = Communication.findBy(communication);
}
public void setGrade(double grade) {
@@ -55,7 +55,9 @@ public class Candidate extends AddressBook {
}
public boolean isEligible() {
- return this.grade >= 85.0;
+ return this.grade >= 85.0
+ || (this.regulatoryCapability >= 0.5
+ && this.communication.isAtLeast(Communication.Average));
}
public static ArrayList<Candidate> getEligibleCandidates(Candidate[] candidates) {
assignments/assignment1/src/main/java/ca/mokhan/assignment1/Communication.java
@@ -13,7 +13,28 @@ public class Communication implements Comparable<Communication> {
return this.ranking.compareTo(other.ranking);
}
+ public boolean isAtLeast(Communication other) {
+ return this.compareTo(other) >= 0;
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+
public static final Communication Poor = new Communication("poor", 0);
public static final Communication Average = new Communication("average", 1);
public static final Communication Excellent = new Communication("excellent", 2);
+
+ public static Communication findBy(String name) {
+ switch (name) {
+ case "poor":
+ return Communication.Poor;
+ case "average":
+ return Communication.Average;
+ case "excellent":
+ return Communication.Excellent;
+ }
+ throw new IllegalArgumentException("Unknown communication type");
+ }
}
assignments/assignment1/src/test/java/ca/mokhan/assignment1/CandidateTest.java
@@ -41,5 +41,6 @@ public class CandidateTest extends TestCase {
public void testIsElligibleWithLessThanRequiredGrade() {
assertFalse(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.0).isEligible());
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.5).isEligible());
}
}
assignments/assignment1/src/test/java/ca/mokhan/assignment1/CommunicationTest.java
@@ -16,11 +16,28 @@ public class CommunicationTest extends TestCase {
public void testCompareTo() {
assertEquals(-1, Communication.Poor.compareTo(Communication.Average));
assertEquals(-1, Communication.Poor.compareTo(Communication.Excellent));
+ assertEquals(0, Communication.Poor.compareTo(Communication.Poor));
assertEquals(-1, Communication.Average.compareTo(Communication.Excellent));
assertEquals(1, Communication.Average.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Average.compareTo(Communication.Average));
assertEquals(1, Communication.Excellent.compareTo(Communication.Average));
assertEquals(1, Communication.Excellent.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Excellent.compareTo(Communication.Excellent));
+ }
+
+ public void testIsAtLeast() {
+ assertFalse(Communication.Poor.isAtLeast(Communication.Average));
+ assertFalse(Communication.Poor.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Poor.isAtLeast(Communication.Poor));
+
+ assertFalse(Communication.Average.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Average.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Average.isAtLeast(Communication.Average));
+
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Average));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Excellent));
}
}