diff --git a/src/code/ca/bcit/comp2522/lab05/BookStore.java b/src/code/ca/bcit/comp2522/lab05/BookStore.java index cde2df1..7d35b7f 100644 --- a/src/code/ca/bcit/comp2522/lab05/BookStore.java +++ b/src/code/ca/bcit/comp2522/lab05/BookStore.java @@ -238,22 +238,28 @@ public class BookStore */ public void getLongest() { - String title; - int longest; - - longest = DEFAULT_LONGEST_VALUE; - title = ""; + Novel longest; + longest = null; for (final Novel novel : this.novels) { - if (novel.getTitle().length() > longest) + if (longest == null) { - longest = novel.getTitle().length(); - title = novel.getTitle(); + longest = novel; + } + else + { + if (novel.getTitle().length() > longest.getTitle().length()) + { + longest = novel; + } } } - System.out.println(title); + if (longest != null) + { + System.out.println(longest.getTitle()); + } } /** diff --git a/src/code/ca/bcit/comp2522/lab06/Main.java b/src/code/ca/bcit/comp2522/lab06/Main.java index 23fcb86..257e6bf 100644 --- a/src/code/ca/bcit/comp2522/lab06/Main.java +++ b/src/code/ca/bcit/comp2522/lab06/Main.java @@ -4,7 +4,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.function.*; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; /** * Demonstrates the use of the HockeyPlayer and HockeyTeam classes along with @@ -25,10 +29,10 @@ public class Main private static final int CURRENT_YEAR = 2025; private static final int HIGH_SCORE_THRESHOLD = 20; private static final String FORWARD_POSITION = "F"; - private static final int MIN_AGE = 21; + private static final int MIN_AGE_YEARS = 21; private static final int MIN_GOALS = 10; private static final int COUNTER_STARTER = 0; - + /** * Creates and returns a sample hockey team with several HockeyPlayer objects. * @@ -84,10 +88,10 @@ public class Main } } - // FUNCTION — transform a HockeyPlayer into a formatted string + // FUNCTION — transform a HockeyPlayer into a formatted string; e.g. final Function playerFunction = - (p) -> p.getPlayerName() + " — " + p.getPosition() - + " (" + p.getGoals() + " goals)"; + (p) -> p.getPlayerName() + " — " + p.getPosition() + + " (" + p.getGoals() + " goals)"; for (final HockeyPlayer p : roster) { @@ -133,12 +137,12 @@ public class Main // FUNCTIONAL INTERFACE (EligibilityRule) // A player is eligible if age >= minAge AND goals >= minGoals final EligibilityRule rule = - (p) -> ((CURRENT_YEAR - p.getYearOfBirth()) >= MIN_AGE) + (p) -> ((CURRENT_YEAR - p.getYearOfBirth()) >= MIN_AGE_YEARS) && (p.getGoals() >= MIN_GOALS); - System.out.println("Eligible players (age >= " - + MIN_AGE + ", goals >= " - + MIN_GOALS + "):"); + System.out.println("Eligible players (age >= " + + MIN_AGE_YEARS + ", goals >= " + + MIN_GOALS + "):"); for (final HockeyPlayer p : roster) {