summaryrefslogtreecommitdiff
path: root/src/Q4/BanffMarathonRunner.java
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
committermokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
commit7b4cb6a2eef3a0fcde7e998832427c73599e4a0a (patch)
tree75acc7cd8f3bd8a087e909db182c9e18a66879a1 /src/Q4/BanffMarathonRunner.java
parent99a28d2dba93642e89a62ecf905a3bd4f138318d (diff)
use the exact naming convention for directories described by instructor
Diffstat (limited to 'src/Q4/BanffMarathonRunner.java')
-rw-r--r--src/Q4/BanffMarathonRunner.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Q4/BanffMarathonRunner.java b/src/Q4/BanffMarathonRunner.java
new file mode 100644
index 0000000..afc0472
--- /dev/null
+++ b/src/Q4/BanffMarathonRunner.java
@@ -0,0 +1,51 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+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);
+ }
+
+ @Override
+ public String toString() {
+ return super.getFirstName() + " " + this.years;
+ }
+
+ public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners) {
+ Arrays.sort(runners);
+ return runners[0];
+ }
+
+ public static BanffMarathonRunner getSecondFastestRunner(BanffMarathonRunner[] runners) {
+ Arrays.sort(runners);
+ return runners[1];
+ }
+
+ public static int getAverageTime(BanffMarathonRunner[] runners) {
+ int sum = 0;
+ for (BanffMarathonRunner runner : runners) sum += runner.time;
+ return sum / runners.length;
+ }
+
+ public static String getAboveAverageRunners(BanffMarathonRunner[] runners) {
+ int average = getAverageTime(runners);
+ ArrayList<String> winners = new ArrayList<String>();
+
+ for (BanffMarathonRunner runner : runners)
+ if (runner.time >= average) winners.add(runner.toString());
+
+ return String.join(System.lineSeparator(), winners);
+ }
+}