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
+29 -19

No files matched your search

+15 -9
View File
@@ -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());
}
}
/**
+14 -10
View File
@@ -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<HockeyPlayer, String> 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)
{