Skip to content

London | 26-Java-June | Fatma Arslantas | Sprint 4 | Rental Summary Generator - #68

Open
AFatmaa wants to merge 8 commits into
CodeYourFuture:mainfrom
AFatmaa:sprint-4-rental-summary-generator
Open

AFatmaa wants to merge 8 commits into
CodeYourFuture:mainfrom
AFatmaa:sprint-4-rental-summary-generator

Conversation

@AFatmaa

@AFatmaa AFatmaa commented Aug 5, 2026 •

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

This PR completes the Sprint 4 Rental Summary Generator ticket.

  • Added models for contracts, monthly rentals and rental summaries
  • Added a RentalCalculator interface
  • Implemented rental generators for one-year and three-year contracts
  • Calculated monthly capital and interest amounts
  • Marked rentals as paid when their due date is today or in the past
  • Sorted rentals by due date
  • Generated summaries with the next due rental, total amounts and outstanding rental count
  • Added handling for completed contracts
  • Added validation for unsupported contract lengths
  • Added the example contracts provided in the ticket
  • Added unit tests for both rental generators
  • Added a service test for unsupported contract lengths

@AFatmaa AFatmaa added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 4 Assigned during Sprint 4 of this module labels Aug 5, 2026
@jwjlord jwjlord added Review in progress and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Sep 2, 2026
@jwjlord jwjlord self-assigned this Sep 2, 2026

@jwjlord jwjlord left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @AFatmaa -- clear and well tested

* @param customerAge the age of the customer
* @param startDate the start date of the contract
* @param contractLengthYears the length of the contract in years
* @param carPrice the price of the car

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When variables are primitive types or quite common reference types it is important to be specific about what they represent. In particular something which often causes confusion is units (such as units of time or currency). Can you think of something which might be useful to add in the documentation to make it clearer what this double variable represents?

Comment thread src/main/java/Rental.java
* Creates a monthly rental payment.
*
* @param dueDate the date the payment is due
* @param capitalAmount the capital part of the payment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import java.util.Optional;

/**
* Represents a summary of a customer's rental contract and payments.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the customer has more than one contract, or has had a contract in the past? Is this just for a certain contract or for all time for that customer?

*/
public class OneYearContractRentalGenerator implements RentalCalculator {

private static final int NUMBER_OF_RENTALS = 12;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


for (int monthNumber = 1; monthNumber <= NUMBER_OF_RENTALS; monthNumber++) {
LocalDate dueDate = contract.getStartDate().plusMonths(monthNumber);
boolean paid = !dueDate.isAfter(currentDate);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me dueDate.isBefore(currentDate) is clearer that !dueDate.isAfter(currentDate) as it's one less logical step to think through (small readability point though!). Was there any particular reason you did it this way? And how did you decide to handle the case where the current date is equal to the due date for one of the rentals?

rentalSummary.ifPresentOrElse(this::printSummary, () -> System.out.println("Contract is completed."));
}

private void printSummary(RentalSummary summary) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

() -> System.out.println("Next due rental: None")
);

System.out.printf("Total capital amount: £%.2f%n", summary.getTotalCapitalAmount());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great use of string formatting here

*/
public void printRentalSummary(Contract contract) {
Optional<RentalSummary> rentalSummary = generateRentalSummary(contract);
rentalSummary.ifPresentOrElse(this::printSummary, () -> System.out.println("Contract is completed."));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gather you've used Optional.empty to signify that the contract is complete here. Can you see any potential issues/ambiguity related to this?

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ThreeYearContractRentalGeneratorTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really good tests here! do you think it would be worth improving them to check all the rentals, or check what happens when some rentals are paid and some are not mid way through the contract? (happy with yes or no -- just would like to know your reasoning)

public class RentalSummaryServiceTest {

@Test
void rejectsUnsupportedContractLength() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way you could improve RentalSummaryService to make it impossible to pass an invalid number of years?

@jwjlord jwjlord added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 4 Assigned during Sprint 4 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants