Skip to content

Add hints document for Meetup exercise #2936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions exercises/practice/meetup/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Hints

## The `java.time` Advantage

Java's modern Date and Time API (`java.time` package, since Java 8) is particularly well-suited for this kind of date calculation exercise.

## Managing Month and Year Context

Your constructor receives the `month` and `year`. While you can use these directly, the `java.time` package offers a convenient class for handling this context:

- [`YearMonth`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/YearMonth.html): Represents a specific month in a specific year. It's useful because it inherently knows the number of days in that particular month, automatically handling leap years.

Check failure on line 11 in exercises/practice/meetup/.docs/hints.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Trailing spaces

exercises/practice/meetup/.docs/hints.md:11:272 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md009.md

## Calculating Specific Dates: `TemporalAdjusters`

The core of this exercise involves finding specific dates based on rules (FIRST, SECOND, TEENTH, LAST, etc.). Instead of manually iterating through days and counting, the `java.time` API provides a powerful utility class designed for exactly these kinds of common date adjustments:

- [`java.time.temporal.TemporalAdjusters`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/temporal/TemporalAdjusters.html) (note the plural 's').

This class is key to solving the exercise idiomatically. Explore its `static` methods. You'll find pre-built adjusters for finding:
- The first or last occurrence of a specific `DayOfWeek` within a month (e.g., `firstInMonth()`, `lastInMonth()`).

Check failure on line 20 in exercises/practice/meetup/.docs/hints.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Lists should be surrounded by blank lines

exercises/practice/meetup/.docs/hints.md:20 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- The first or last occurrence..."] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md032.md
- The Nth occurrence of a specific `DayOfWeek` within a month (e.g., `dayOfWeekInMonth()`).
- The next occurrence of a specific `DayOfWeek` from a given date (e.g., `nextOrSame()`, which is helpful for the `TEENTH` case).

## Applying Adjustments

- A `TemporalAdjuster` (obtained from a static method in `TemporalAdjusters`) is typically used with the `.with(TemporalAdjuster)` method on a `LocalDate` instance. This method returns a *new* `LocalDate` reflecting the adjustment.

Check failure on line 26 in exercises/practice/meetup/.docs/hints.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Files should end with a single newline character

exercises/practice/meetup/.docs/hints.md:26:231 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md047.md
Loading