Commit a6b37a8
Changed files (3)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
test
java
ca
mokhan
assignment1
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
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];
+ }
+}
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));
+ }
+}