summaryrefslogtreecommitdiff
path: root/src/Q4
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q4')
-rw-r--r--src/Q4/BanffMarathonRunner.java148
-rw-r--r--src/Q4/BanffMarathonRunnerTest.java63
-rw-r--r--src/Q4/README.md140
3 files changed, 0 insertions, 351 deletions
diff --git a/src/Q4/BanffMarathonRunner.java b/src/Q4/BanffMarathonRunner.java
deleted file mode 100644
index d9f5617..0000000
--- a/src/Q4/BanffMarathonRunner.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Assignment 1, COMP268 Class: BanffMarathonRunner.java
- *
- * @description Represents a marathon runner
- * @author: mo khan Student ID: 3431709
- * @date May 8, 2019
- * @version 1.0
- */
-package Q4;
-
-import Q1.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-public class BanffMarathonRunner extends AddressBook {
- private int time;
- private int years;
-
- /**
- * Constructs a BanffMarathonRunner object.
- *
- * @param firstName the first name of the runner
- * @param lastName the last name of the runner
- * @param time the time it took the runner to complete the marathon
- * @param years the number of years they participated
- */
- public BanffMarathonRunner(String firstName, String lastName, int time, int years) {
- super(firstName, "", lastName);
- this.time = time;
- this.years = years;
- }
-
- /**
- * Performs a comparison of this runner with another based on the time it took them to complete
- * the marathon. Because java generics does not allow implementing a generic interface with
- * different type parameters, this code assumes the AddressBook is an instance of a Runner.
- *
- * @param other the other runner to compare against
- * @return a negative integer, zero, or a positive integer as the first argument is less than,
- * equal to, or greater than the second.
- */
- public int compareTo(AddressBook other) {
- BanffMarathonRunner runner = (BanffMarathonRunner) other;
- return Integer.compare(this.time, runner.time);
- }
-
- /**
- * Return the time take to complete the race.
- *
- * @return the time taken to complete the race
- */
- public int getTime() {
- return this.time;
- }
-
- /**
- * Returns a string representation of the runner.
- *
- * @return The first name + the # of years that they participated.
- */
- @Override
- public String toString() {
- return super.getFirstName() + " " + this.years;
- }
-
- /**
- * Sorts the list of runners based on time, then returns the fastest runner.
- *
- * @param runners the list of runners.
- * @return the fastest runner
- */
- public static BanffMarathonRunner getFastestRunner(BanffMarathonRunner[] runners) {
- Arrays.sort(runners);
- return runners[0];
- }
-
- /**
- * Sorts the list of runners based on time, then returns the second fastest runner.
- *
- * @param runners the list of runners.
- * @return the second fastest runner
- */
- public static BanffMarathonRunner getSecondFastestRunner(BanffMarathonRunner[] runners) {
- Arrays.sort(runners);
- return runners[1];
- }
-
- /**
- * Calculates the average time that it took the runners to complete the marathon.
- *
- * @param runners the array of runners.
- * @return the average time taken to complete the marathon
- */
- public static int getAverageTime(BanffMarathonRunner[] runners) {
- int sum = 0;
- for (BanffMarathonRunner runner : runners) sum += runner.time;
- return sum / runners.length;
- }
-
- /**
- * Returns the runners that finished the marathon in above or equal to average time.
- *
- * @param runners the list of runners
- * @return the list of runners that finished the marathon in above average time.
- */
- 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);
- }
-
- public static void main(String[] args) {
- BanffMarathonRunner[] runners = {
- new BanffMarathonRunner("Elena", "Brandon", 341, 1),
- new BanffMarathonRunner("Thomas", "Molson", 273, 2),
- new BanffMarathonRunner("Hamilton", "Winn", 278, 5),
- new BanffMarathonRunner("Suzie", "Sarandin", 329, 7),
- new BanffMarathonRunner("Philip", "Winne", 445, 9),
- new BanffMarathonRunner("Alex", "Trebok", 275, 3),
- new BanffMarathonRunner("Emma", "Pivoto", 275, 4),
- new BanffMarathonRunner("John", "Lenthen", 243, 1),
- new BanffMarathonRunner("James", "Lean", 334, 1),
- new BanffMarathonRunner("Jane", "Ostin", 412, 1),
- new BanffMarathonRunner("Emily", "Car", 393, 4),
- new BanffMarathonRunner("Daniel", "Hamshire", 299, 4),
- new BanffMarathonRunner("Neda", "Bazdar", 343, 3),
- new BanffMarathonRunner("Aaron", "Smith", 317, 6),
- new BanffMarathonRunner("Kate", "Hen", 265, 8)
- };
-
- BanffMarathonRunner fastestRunner = BanffMarathonRunner.getFastestRunner(runners);
- System.out.println(fastestRunner.getFirstName());
- System.out.println(fastestRunner.getHomeAddress());
- System.out.println(fastestRunner.getTime());
-
- BanffMarathonRunner secondFastestRunner = BanffMarathonRunner.getSecondFastestRunner(runners);
- System.out.println(secondFastestRunner.getFirstName());
- System.out.println(secondFastestRunner.getHomeAddress());
- System.out.println(secondFastestRunner.getTime());
- System.out.println(secondFastestRunner.getTime() - fastestRunner.getTime());
-
- System.out.print(BanffMarathonRunner.getAboveAverageRunners(runners));
- }
-}
diff --git a/src/Q4/BanffMarathonRunnerTest.java b/src/Q4/BanffMarathonRunnerTest.java
deleted file mode 100644
index 5e41380..0000000
--- a/src/Q4/BanffMarathonRunnerTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package ca.mokhan.test;
-
-import Q4.*;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class BanffMarathonRunnerTest extends TestCase {
- private BanffMarathonRunner john = new BanffMarathonRunner("John", "Lenthen", 243, 1);
- private BanffMarathonRunner kate = new BanffMarathonRunner("Kate", "Hen", 265, 8);
- private BanffMarathonRunner[] runners = {
- new BanffMarathonRunner("Elena", "Brandon", 341, 1),
- new BanffMarathonRunner("Thomas", "Molson", 273, 2),
- new BanffMarathonRunner("Hamilton", "Winn", 278, 5),
- new BanffMarathonRunner("Suzie", "Sarandin", 329, 7),
- new BanffMarathonRunner("Philip", "Winne", 445, 9),
- new BanffMarathonRunner("Alex", "Trebok", 275, 3),
- new BanffMarathonRunner("Emma", "Pivoto", 275, 4),
- this.john,
- new BanffMarathonRunner("James", "Lean", 334, 1),
- new BanffMarathonRunner("Jane", "Ostin", 412, 1),
- new BanffMarathonRunner("Emily", "Car", 393, 4),
- new BanffMarathonRunner("Daniel", "Hamshire", 299, 4),
- new BanffMarathonRunner("Neda", "Bazdar", 343, 3),
- new BanffMarathonRunner("Aaron", "Smith", 317, 6),
- this.kate
- };
-
- public BanffMarathonRunnerTest(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(BanffMarathonRunnerTest.class);
- }
-
- public void testGetFastestRunner() {
- assertEquals(this.john, BanffMarathonRunner.getFastestRunner(this.runners));
- }
-
- public void testGetSecondFastestRunner() {
- assertEquals(this.kate, BanffMarathonRunner.getSecondFastestRunner(this.runners));
- }
-
- public void testGetAverageTime() {
- assertEquals(321, BanffMarathonRunner.getAverageTime(this.runners));
- }
-
- public void testGetAboveAverageRunners() {
- String expected =
- String.join(
- System.lineSeparator(),
- "Thomas 2",
- "Hamilton 5",
- "Alex 3",
- "Emma 4",
- "John 1",
- "Daniel 4",
- "Aaron 6",
- "Kate 8");
- assertEquals(expected, BanffMarathonRunner.getAboveAverageRunners(this.runners));
- }
-}
diff --git a/src/Q4/README.md b/src/Q4/README.md
deleted file mode 100644
index 80a84eb..0000000
--- a/src/Q4/README.md
+++ /dev/null
@@ -1,140 +0,0 @@
-Learning Profile for Assignment #1, And Question #4
-
-Name: Mo Khan
-Student ID: 3431709
-
-1. Problem Statement:
-
-A group of AU friends decide to run the Banff, Alberta, Marathon.
-Their names, times (marathon completion time in minutes), and number of years participated are given below:
-
-| id | Name | time (mins) | years |
-| --- | --- | --- | --- |
-| 1 | Elena Brandon | 341 | 1 |
-| 2 | Thomas Molson | 273 | 2 |
-| 3 | Hamilton Winn | 278 | 5 |
-| 4 | Suzie Sarandin | 329 | 7 |
-| 5 | Philip Winne | 445 | 9 |
-| 6 | Alex Trebok | 275 | 3 |
-| 7 | Emma Pivoto | 275 | 4 |
-| 8 | John Lenthen | 243 | 1 |
-| 9 | James Lean | 334 | 1 |
-| 10 | Jane Ostin | 412 | 1 |
-| 11 | Emily Car | 393 | 4 |
-| 12 | Daniel Hamshire | 299 | 4 |
-| 13 | Neda Bazdar | 343 | 3 |
-| 14 | Aaron Smith | 317 | 6 |
-| 15 | Kate Hen | 265 | 8|
-
-Extend the AddressBook class from Problem 1 to store the additional data.
-Now, write a method to find the fastest runner.
-Print the name, address, and his/her time (in minutes) on three separate lines.
-Find the second fastest runner.
-Print the name, address, his/her time (in minutes), and the difference in time with the fastest runner.
-Compute the average time of completion taken by these runners.
-Finally, print the name and number of years participated for each runner if the runner’s time of completion is equal to or better than the average time of completion.
-
-2. Description of the Code:
-
-[Briefly describe how you solved the problem in your code. You should include short description of classes, methods, and variables (if necessary) that you used in your code.]
-
-I followed the instructions in the assignment and created a class the
-inherits from `AddressBook`. The sub class has a single constructor that
-chains to the super class constructor.
-
-I did an override of the `Comparable<AddressBook>` interface to compare
-using the runners time instead of the default comparison from the base
-class.
-
-Java's implementation of generics doesn't allow a class to
-implement the same generic interface using a different type parameter.
-So I had to downcast the `AddressBook` to a `BanffMarathonRunner`. The
-`compareTo` implementation in the subclass always assums that it is
-being compared to another `BanffMarathonRunner`.
-
-Sorting arrays becomes very using after implementing the `Comparable<T>`
-interface.
-
-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 46 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.05 sec
-Running ca.mokhan.test.NumberTest
-Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 sec
-Running ca.mokhan.test.EmployeeSavingsTest
-Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 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 sec
-Running ca.mokhan.test.HailstoneSequenceTest
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
-
-Results :
-
-Tests run: 52, Failures: 0, Errors: 0, Skipped: 0
-
-[INFO] ------------------------------------------------------------------------
-[INFO] BUILD SUCCESS
-[INFO] ------------------------------------------------------------------------
-[INFO] Total time: 2.893 s
-[INFO] Finished at: 2019-05-13T21:20:12-06:00
-[INFO] ------------------------------------------------------------------------
-```
-
-
-4. Sample Input and Output:
-
-Tests are available in `BanffMarathonRunnerTest.java`.
-
-5. Discussion:
-
-The implementation of `getAboveAverageRunners` assumes that `better`
-is less than or equal to the average time taken by all runners.