diff options
| author | mo <mo.khan@gmail.com> | 2019-05-25 15:27:51 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-05-25 15:27:51 -0600 |
| commit | 856c35dbc7080922bfff7c10a7a844a9d0a1cd65 (patch) | |
| tree | 739b413bc2a29adc35229ef2fd9b30581601a206 /src/Q8 | |
| parent | 46f68298527e0c59b9f34003b687259477093fde (diff) | |
start assignment 2
Diffstat (limited to 'src/Q8')
| -rw-r--r-- | src/Q8/Candidate.java | 147 | ||||
| -rw-r--r-- | src/Q8/CandidateTest.java | 63 | ||||
| -rw-r--r-- | src/Q8/Communication.java | 76 | ||||
| -rw-r--r-- | src/Q8/CommunicationTest.java | 44 | ||||
| -rw-r--r-- | src/Q8/README.md | 121 |
5 files changed, 0 insertions, 451 deletions
diff --git a/src/Q8/Candidate.java b/src/Q8/Candidate.java deleted file mode 100644 index 2024267..0000000 --- a/src/Q8/Candidate.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Assignment 1, COMP268 Class: Candidate.java - * - * @description Represents a candidate - * @author: mo khan Student ID: 3431709 - * @date May 8, 2019 - * @version 1.0 - */ -package Q8; - -import Q1.*; -import java.util.ArrayList; -import java.util.Scanner; - -public class Candidate extends AddressBook { - private double grade = 0.0; - private Communication communication; - private boolean isInnovative; - private double regulatoryCapability; - - /** - * Constructs a Candidate object. - * - * @param firstName the first name of the runner - * @param lastName the last name of the runner - * @param grade the grade for the candidate - * @param communication the level of communication - * @param isInnovative specifies if the candidate is innovative. - * @param regulatoryCapability specifies the candidates level of regulatory capability - */ - public Candidate( - String firstName, - String lastName, - double grade, - String communication, - boolean isInnovative, - double regulatoryCapability) { - super(firstName, "", lastName); - this.grade = grade; - this.setCommunication(communication); - this.isInnovative = isInnovative; - this.regulatoryCapability = regulatoryCapability; - } - - /** @return the candidates innovativeness. */ - public boolean isInnovative() { - return this.isInnovative; - } - - /** @return the candidates grade. */ - public double getGrade() { - return this.grade; - } - - /** @return the candidates regulatory capability */ - public double getRegulation() { - return this.regulatoryCapability; - } - - /** @return the candidates communication ability */ - public String getCommunication() { - return this.communication.toString(); - } - - /** - * Sets the candidate communication level. - * - * @param communication the candidates communication ability - */ - public void setCommunication(String communication) { - this.communication = Communication.findBy(communication); - } - - /** - * Sets the candidate grade level. - * - * @param grade the candidates grade - */ - public void setGrade(double grade) { - this.grade = grade; - } - - /** - * Sets the candidate innovation level. - * - * @param innovation the candidates innovation ability - */ - public void setInnovation(boolean innovation) { - this.isInnovative = innovation; - } - - /** - * Sets the candidate regulatory capability level. - * - * @param regulatoryCapability the candidates regulatory capability - */ - public void setRegulation(double regulatoryCapability) { - this.regulatoryCapability = regulatoryCapability; - } - - /** @return true if the candidate is eligible for a position at the company. */ - public boolean isEligible() { - if (this.grade >= 85.0) { - return this.communication.isAtLeast(Communication.Average) || this.isInnovative(); - } else { - return (this.regulatoryCapability >= 0.5 - && this.communication.isAtLeast(Communication.Average)); - } - } - - /** - * @param candidates the list of candidates to check for qualifications - * @return a list of candidates that are eligible for employment at the company. - */ - public static ArrayList<Candidate> getEligibleCandidates(Candidate[] candidates) { - ArrayList<Candidate> eligible = new ArrayList<Candidate>(); - - for (Candidate candidate : candidates) if (candidate.isEligible()) eligible.add(candidate); - - return eligible; - } - - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - - Candidate[] candidates = { - new Candidate("Elena", "Brandon", 82.30, "poor", true, 0.5), - new Candidate("Thomas", "Molson", 85.10, "poor", false, 1.0), - new Candidate("Hamilton", "Winn", 77.77, "average", false, 0.8), - new Candidate("Suzie", "Sarandin", 69.93, "average", false, 0.0), - new Candidate("Philip", "Winne", 93.03, "average", true, 1.0), - new Candidate("Alex", "Trebok", 88.61, "poor", true, 0.7), - new Candidate("Emma", "Pivoto", 55.99, "excellent", false, 0.8), - new Candidate("John", "Lenthen", 87.49, "excellent", true, 0.9), - new Candidate("James", "Lean", 88.00, "excellent", false, 0.5), - new Candidate("Jane", "Ostin", 91.20, "average", true, 0.6), - new Candidate("Emily", "Car", 66.79, "excellent", false, 0.3), - new Candidate("Daniel", "Hamshire", 76.65, "average", true, 0.2), - new Candidate("Neda", "Bazdar", 55.89, "excellent", true, 0.5), - new Candidate("Aaron", "Smith", 90.01, "excellent", false, 0.3), - new Candidate("Kate", "Hen", 87.9, "poor", false, 0.8) - }; - - for (Candidate candidate : Candidate.getEligibleCandidates(candidates)) - System.out.println(candidate); - } -} diff --git a/src/Q8/CandidateTest.java b/src/Q8/CandidateTest.java deleted file mode 100644 index 56513b8..0000000 --- a/src/Q8/CandidateTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package ca.mokhan.test; - -import Q8.*; -import java.util.ArrayList; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class CandidateTest extends TestCase { - private Candidate[] candidates = { - new Candidate("Elena", "Brandon", 82.30, "poor", true, 0.5), - new Candidate("Thomas", "Molson", 85.10, "poor", false, 1.0), - new Candidate("Hamilton", "Winn", 77.77, "average", false, 0.8), - new Candidate("Suzie", "Sarandin", 69.93, "average", false, 0.0), - new Candidate("Philip", "Winne", 93.03, "average", true, 1.0), - new Candidate("Alex", "Trebok", 88.61, "poor", true, 0.7), - new Candidate("Emma", "Pivoto", 55.99, "excellent", false, 0.8), - new Candidate("John", "Lenthen", 87.49, "excellent", true, 0.9), - new Candidate("James", "Lean", 88.00, "excellent", false, 0.5), - new Candidate("Jane", "Ostin", 91.20, "average", true, 0.6), - new Candidate("Emily", "Car", 66.79, "excellent", false, 0.3), - new Candidate("Daniel", "Hamshire", 76.65, "average", true, 0.2), - new Candidate("Neda", "Bazdar", 55.89, "excellent", true, 0.5), - new Candidate("Aaron", "Smith", 90.01, "excellent", false, 0.3), - new Candidate("Kate", "Hen", 87.9, "poor", false, 0.8) - }; - - public CandidateTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(CandidateTest.class); - } - - public void testGetEligibleCandidates() { - ArrayList<Candidate> eligibleCandidates = Candidate.getEligibleCandidates(this.candidates); - for (String expected : - new String[] { - "Hamilton", "Philip", "Alex", "Emma", "John", "James", "Jane", "Neda", "Aaron" - }) { - assertNotNull( - eligibleCandidates.stream() - .filter(x -> expected.equals(x.getFirstName())) - .findAny() - .orElse(null)); - } - } - - public void testIsElligibleWithGreaterThanRequiredGrade() { - assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "excellent", false, 0.0).isEligible()); - } - - 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()); - } - - public void testIsElligibleWithPoorCommunication() { - assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", true, 0.0).isEligible()); - assertFalse(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", false, 0.0).isEligible()); - } -} diff --git a/src/Q8/Communication.java b/src/Q8/Communication.java deleted file mode 100644 index cc217e3..0000000 --- a/src/Q8/Communication.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Assignment 1, COMP268 Class: Communication.java - * - * @description Represents a candidates communication ability. - * @author: mo khan Student ID: 3431709 - * @date May 8, 2019 - * @version 1.0 - */ -package Q8; - -public class Communication implements Comparable<Communication> { - private String name; - private Integer ranking; - - /** - * Constructs a Communication object. - * - * @param name the name of the communication level - * @param ranking the ranking of the communication level. - */ - public Communication(String name, Integer ranking) { - this.name = name; - this.ranking = ranking; - } - - /** - * Compares one communication level with another. - * - * @param other the other communication level to compare against - * @return a negative integer, zero, or a positive integer as this object is less than, equal to, - * or greater than the specified object. - */ - public int compareTo(Communication other) { - return this.ranking.compareTo(other.ranking); - } - - /** - * Compares one communication level with another. - * - * @param other the other communication level to compare against - * @return true if this communication level is equal to or better than the other. - */ - public boolean isAtLeast(Communication other) { - return this.compareTo(other) >= 0; - } - - /** - * The string representation of the candidate. - * - * @return the name of the candidate - */ - @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); - - /** - * @param name of the communication level to find. - * @return the Communication level matching the name - */ - 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"); - } -} diff --git a/src/Q8/CommunicationTest.java b/src/Q8/CommunicationTest.java deleted file mode 100644 index c2bdfa3..0000000 --- a/src/Q8/CommunicationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package ca.mokhan.test; - -import Q8.*; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class CommunicationTest extends TestCase { - public CommunicationTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(CommunicationTest.class); - } - - 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)); - } -} diff --git a/src/Q8/README.md b/src/Q8/README.md deleted file mode 100644 index 706d676..0000000 --- a/src/Q8/README.md +++ /dev/null @@ -1,121 +0,0 @@ -Learning Profile for Assignment #1, And Question #8 - -Name: Mo Khan -Student ID: 3431709 - -1. Problem Statement: - -Google Inc. is looking to recruit three of the Boston runners. - -The criteria for selection are as follows: - -* I. Average final marks in bachelor’s degree (store up to 2 decimal places). - The fifteen candidates have the following grades: 82.30%, 85.10%, 77.77%, 69.93%, 93.03%, 88.61%, 55.99%, 87.49%, 88.00%, 91.20%, 66.79%, 76.65%, 55.89%, 90.01%, and 87.9%. -* II. Ability to communicate as one of the three values – "excellent", "average", and "poor". - The fifteen candidates have the following ability to communicate, respectively: poor, poor, average, average, average, poor, excellent, excellent, excellent, average, excellent, average, excellent, excellent, poor. -* III. Innovation as one of the two values – "brilliant" and "average" (store as a Boolean; brilliant = true and average = false). - The fifteen candidates have the following innovative abilities: brilliant, average, average, average, brilliant, brilliant, average, brilliant, average, brilliant, average, brilliant, brilliant, average, average. -* IV. Ability to regulate one’s own skill as a probability value between 0 and 1.0 – 1.0 implies excellent regulatory capabilities and 0.0 implies no skills to regulate (store as a double). - The fifteen candidates have the following regulatory abilities: 0.5, 1.0, 0.8, 0.0, 1.0, 0.7, 0.8, 0.9, 0.5, 0.6, 0.3, 0.2, 0.5, 0.3, 0.8. - -Store these values for the fifteen candidates in an extended AddressBook class. - -In general, Google will not consider a candidate with average marks of less than 85%. - -Google will consider a candidate with average marks of less than 85% only if the candidate at least has 0.5 regulatory abilities and at least 'average' ability to communicate. - -Google will only consider a candidate with poor communication ability if the candidate has a 'brilliant' innovation capability. - -Write a program that will help Google to programmatically determine eligibility of the fifteen candidates for these positions, and print the output on the console. - -2. Description of the Code: - -I created two classes to solve this problem. The first class is the -`Candidate` class and the second is the `Communication` class. I used -the `Communication` class to control sort order and precedence of one -communication level with another using the `Comparable<T>` interface. - -In the `Candidate` class I created a method called `isEligible` that -calculates if the candidate is eligible for a position at the company. - -3. Errors and Warnings: - -```bash -モ mvn test -[INFO] Scanning for projects... -[INFO] -[INFO] -------------------< ca.mokhan.comp268:assignment1 >-------------------- -[INFO] Building assignment1 1.0-SNAPSHOT -[INFO] --------------------------------[ jar ]--------------------------------- -[INFO] -[INFO] --- fmt-maven-plugin:2.8:format (default) @ assignment1 --- -[INFO] Processed 47 files (0 reformatted). -[INFO] -[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assignment1 --- -[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/main/resources -[INFO] -[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assignment1 --- -[INFO] Changes detected - recompiling the module! -[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! -[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/classes -[INFO] -[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assignment1 --- -[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -[INFO] skip non existing resourceDirectory /Users/mokha/development/gh/comp-268/src/test/resources -[INFO] -[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assignment1 --- -[INFO] Changes detected - recompiling the module! -[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! -[INFO] Compiling 24 source files to /Users/mokha/development/gh/comp-268/target/test-classes -[INFO] -[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assignment1 --- -[INFO] Surefire report directory: /Users/mokha/development/gh/comp-268/target/surefire-reports - -------------------------------------------------------- - T E S T S -------------------------------------------------------- -Running ca.mokhan.comp268.AppTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec -Running ca.mokhan.test.CandidateTest -Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.057 sec -Running ca.mokhan.test.NumberTest -Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 sec -Running ca.mokhan.test.EmployeeSavingsTest -Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec -Running ca.mokhan.test.CartesianCoordinateSystemTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.CommunicationTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.TaxReturnTest -Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.BanffMarathonRunnerTest -Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.AddressBookTest -Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.TriangleTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec -Running ca.mokhan.test.BonusOnSavingsTest -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec -Running ca.mokhan.test.HailstoneSequenceTest -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - -Results : - -Tests run: 52, Failures: 0, Errors: 0, Skipped: 0 - -[INFO] ------------------------------------------------------------------------ -[INFO] BUILD SUCCESS -[INFO] ------------------------------------------------------------------------ -[INFO] Total time: 2.907 s -[INFO] Finished at: 2019-05-13T21:37:20-06:00 -[INFO] ------------------------------------------------------------------------ -``` - - -4. Sample Input and Output: - -Tests are available in `CandidateTest.java` and `CommunicationTest.java`. - - -5. Discussion: |
