Skip to content

London | 26-Java-June | Shaghayegh far | Sprint 4 | Car rental generator - #58

Open
shaghayeghfar wants to merge 1 commit into
CodeYourFuture:mainfrom
shaghayeghfar:rental-summary-generator
Open

shaghayeghfar wants to merge 1 commit into
CodeYourFuture:mainfrom
shaghayeghfar:rental-summary-generator

Conversation

@shaghayeghfar

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

I Implemented the Rental Summary Generator with contract validation, rental generation for 1 and 3-year contracts.

@shaghayeghfar shaghayeghfar added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 29, 2026
@jwjlord
jwjlord self-requested a review August 17, 2026 10:09

@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.

Looks good @shaghayeghfar, I can see that you've understood how to use interfaces correctly which is great! The main points to consider are:

  • I don't think you've called markAsPaid anywhere
  • I think you're missing unit testing for your key services
    An extension question to think about if you have time: is there any reason you structured your packages the way you did? Can you think about a different way to structure them which could be used in tandem with class visibility modifiers to isolate the code in the implementation classes (i.e. so that other services can only see the interface, not the specific implementations)? What would be the advantage of doing this?


import java.util.List;

public interface RentalCalculator {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be useful to have Javadoc on this interface and its method


import java.time.LocalDate;

public class Contract {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Javadoc


import java.time.LocalDate;

public class Rental {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Javadoc

public boolean isPaid() {
return paid;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consistent formatting (for example, consistent spacing between methods) makes the code a bit easier to read -- you can use Ctrl + Alt + L in Intellij to auto-format a whole class for you

import java.time.LocalDate;
import java.util.List;

public class RentalSummary {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Javadoc


public static void main(String[] args) {

Contract contract = new Contract(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How would you change this to make it possible for the user to input data about a contract?

RentalSummary summary = service.generateRentalSummary(contract);


System.out.println(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.

It looks like you're relying on the toString implementation of RentalSummary here. Can you imagine any disadvantages to this approach? What if we wanted to translate the output into a different language, for example?

import java.util.ArrayList;
import java.util.List;

public class OneYearContractRentalGenerator implements RentalCalculator {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Javadoc

import java.util.ArrayList;
import java.util.List;

public class ThreeYearsContractRentalGenerator implements RentalCalculator {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Javadoc

totalCapital += rental.getCapitalAmount();
totalInterest += rental.getInterestAmount();

if (!rental.isPaid()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This makes sense, but I can't see where the rentals are being marked as paid (I might be missing something). So as far as I understand, isPaid will be false for all rentals regardless of the current date.

@jwjlord jwjlord added Complete Volunteer to add when work is complete and all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress Complete Volunteer to add when work is complete and all review comments have been addressed. labels Aug 17, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants