diff options
| author | mokha <mokha@cisco.com> | 2019-04-28 18:05:49 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2019-04-28 18:05:49 -0600 |
| commit | a6b37a857606f381a32dfeeb0f3fbfaad4d2596a (patch) | |
| tree | 52ebac2713bc6d65968bc28429ce84815e9d12b2 | |
| parent | 8c37add65db2f79aa533b8eee67ff7c28ed0dc5b (diff) | |
getFastestRunner()
3 files changed, 80 insertions, 9 deletions
diff --git a/assignments/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java b/assignments/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java index 08b5687..9aac79c 100644 --- a/assignments/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java +++ b/assignments/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java @@ -80,15 +80,15 @@ public class AddressBook implements Comparable<AddressBook> if (!(o instanceof AddressBook)) return false; AddressBook that = (AddressBook) o; return Objects.equals(businessPhone, that.businessPhone) && - Objects.equals(cellPhone, that.cellPhone) && - Objects.equals(facebookId, that.facebookId) && - Objects.equals(firstName, that.firstName) && - Objects.equals(homeAddress, that.homeAddress) && - Objects.equals(homePhone, that.homePhone) && - Objects.equals(lastName, that.lastName) && - Objects.equals(middleName, that.middleName) && - Objects.equals(personalWebSite, that.personalWebSite) && - Objects.equals(skypeId, that.skypeId); + Objects.equals(cellPhone, that.cellPhone) && + Objects.equals(facebookId, that.facebookId) && + Objects.equals(firstName, that.firstName) && + Objects.equals(homeAddress, that.homeAddress) && + Objects.equals(homePhone, that.homePhone) && + Objects.equals(lastName, that.lastName) && + Objects.equals(middleName, that.middleName) && + Objects.equals(personalWebSite, that.personalWebSite) && + Objects.equals(skypeId, that.skypeId); } @Override diff --git a/assignments/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java b/assignments/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java new file mode 100644 index 0000000..1b27366 --- /dev/null +++ b/assignments/assignment1/src/main/java/ca/mokhan/assignment1/BanffMarathonRunner.java @@ -0,0 +1,28 @@ +package ca.mokhan.assignment1; + +import java.util.Arrays; +import java.util.Objects; + +public class BanffMarathonRunner extends AddressBook +{ + private int time; + private int years; + + public BanffMarathonRunner(String firstName, String lastName, int time, int years) { + super(firstName, "", lastName); + this.time = time; + this.years = years; + } + + public int compareTo(AddressBook other) + { + BanffMarathonRunner runner = (BanffMarathonRunner)other; + return Integer.compare(this.time, runner.time); + } + + public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners) + { + Arrays.sort(runners); + return runners[0]; + } +} diff --git a/assignments/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java b/assignments/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java new file mode 100644 index 0000000..728e886 --- /dev/null +++ b/assignments/assignment1/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java @@ -0,0 +1,43 @@ +package ca.mokhan.assignment1; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class BanffMarathonRunnerTest extends TestCase +{ + private BanffMarathonRunner john; + private BanffMarathonRunner[] runners = new BanffMarathonRunner[15]; + + public BanffMarathonRunnerTest(String testName) + { + super(testName); + this.john = new BanffMarathonRunner("John", "Lenthen", 243, 1); + + this.runners[0] = new BanffMarathonRunner("Elena", "Brandon", 341, 1); + this.runners[1] = new BanffMarathonRunner("Thomas", "Molson", 273, 2); + this.runners[2] = new BanffMarathonRunner("Hamilton", "Winn", 278, 5); + this.runners[3] = new BanffMarathonRunner("Suzie", "Sarandin", 329, 7); + this.runners[4] = new BanffMarathonRunner("Philip", "Winne", 445, 9); + this.runners[5] = new BanffMarathonRunner("Alex", "Trebok", 275, 3); + this.runners[6] = new BanffMarathonRunner("Emma", "Pivoto", 275, 4); + this.runners[7] = this.john; + this.runners[8] = new BanffMarathonRunner("James", "Lean", 334, 1); + this.runners[9] = new BanffMarathonRunner("Jane", "Ostin", 412, 1); + this.runners[10] = new BanffMarathonRunner("Emily", "Car", 393, 4); + this.runners[11] = new BanffMarathonRunner("Daniel", "Hamshire", 299, 4); + this.runners[12] = new BanffMarathonRunner("Neda", "Bazdar", 343, 3); + this.runners[13] = new BanffMarathonRunner("Aaron", "Smith", 317, 6); + this.runners[14] = new BanffMarathonRunner("Kate", "Hen", 265, 8); + } + + public static Test suite() + { + return new TestSuite(BanffMarathonRunnerTest.class); + } + + public void testGetFastestRunner() + { + assertEquals(this.john, BanffMarathonRunner.getFastestRunner(this.runners)); + } +} |
