add recommended changes

This commit is contained in:
SowinskiBraeden committed 2025-11-03 14:19:07 -08:00
1 parent 935f745836
commit 812e58d3eb
2 files changed
+28 -18

No files matched your search

+15 -9
View File
@@ -238,22 +238,28 @@ public class BookStore
*/ */
public void getLongest() public void getLongest()
{ {
String title; Novel longest;
int longest; longest = null;
longest = DEFAULT_LONGEST_VALUE;
title = "";
for (final Novel novel : this.novels) for (final Novel novel : this.novels)
{ {
if (novel.getTitle().length() > longest) if (longest == null)
{ {
longest = novel.getTitle().length(); longest = novel;
title = novel.getTitle(); }
else
{
if (novel.getTitle().length() > longest.getTitle().length())
{
longest = novel;
}
} }
} }
System.out.println(title); if (longest != null)
{
System.out.println(longest.getTitle());
}
} }
/** /**
+13 -9
View File
@@ -4,7 +4,11 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; 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 * Demonstrates the use of the HockeyPlayer and HockeyTeam classes along with
@@ -25,7 +29,7 @@ public class Main
private static final int CURRENT_YEAR = 2025; private static final int CURRENT_YEAR = 2025;
private static final int HIGH_SCORE_THRESHOLD = 20; private static final int HIGH_SCORE_THRESHOLD = 20;
private static final String FORWARD_POSITION = "F"; 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 MIN_GOALS = 10;
private static final int COUNTER_STARTER = 0; private static final int COUNTER_STARTER = 0;
@@ -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<HockeyPlayer, String> playerFunction = final Function<HockeyPlayer, String> playerFunction =
(p) -> p.getPlayerName() + "" + p.getPosition() (p) -> p.getPlayerName() + "" + p.getPosition() +
+ " (" + p.getGoals() + " goals)"; " (" + p.getGoals() + " goals)";
for (final HockeyPlayer p : roster) for (final HockeyPlayer p : roster)
{ {
@@ -133,12 +137,12 @@ public class Main
// FUNCTIONAL INTERFACE (EligibilityRule) // FUNCTIONAL INTERFACE (EligibilityRule)
// A player is eligible if age >= minAge AND goals >= minGoals // A player is eligible if age >= minAge AND goals >= minGoals
final EligibilityRule rule = final EligibilityRule rule =
(p) -> ((CURRENT_YEAR - p.getYearOfBirth()) >= MIN_AGE) (p) -> ((CURRENT_YEAR - p.getYearOfBirth()) >= MIN_AGE_YEARS)
&& (p.getGoals() >= MIN_GOALS); && (p.getGoals() >= MIN_GOALS);
System.out.println("Eligible players (age >= " System.out.println("Eligible players (age >= " +
+ MIN_AGE + ", goals >= " MIN_AGE_YEARS + ", goals >= " +
+ MIN_GOALS + "):"); MIN_GOALS + "):");
for (final HockeyPlayer p : roster) for (final HockeyPlayer p : roster)
{ {