Repository navigation
Conversation
| * @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 |
There was a problem hiding this comment.
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?
| * Creates a monthly rental payment. | ||
| * | ||
| * @param dueDate the date the payment is due | ||
| * @param capitalAmount the capital part of the payment |
There was a problem hiding this comment.
Similar comment to that made in Contract: https://github.com/CodeYourFuture/Module-Java/pull/68/changes#r3915846318
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Represents a summary of a customer's rental contract and payments. |
There was a problem hiding this comment.
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; |
|
|
||
| for (int monthNumber = 1; monthNumber <= NUMBER_OF_RENTALS; monthNumber++) { | ||
| LocalDate dueDate = contract.getStartDate().plusMonths(monthNumber); | ||
| boolean paid = !dueDate.isAfter(currentDate); |
There was a problem hiding this comment.
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) { |
| () -> System.out.println("Next due rental: None") | ||
| ); | ||
|
|
||
| System.out.printf("Total capital amount: £%.2f%n", summary.getTotalCapitalAmount()); |
| */ | ||
| public void printRentalSummary(Contract contract) { | ||
| Optional<RentalSummary> rentalSummary = generateRentalSummary(contract); | ||
| rentalSummary.ifPresentOrElse(this::printSummary, () -> System.out.println("Contract is completed.")); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Any way you could improve RentalSummaryService to make it impossible to pass an invalid number of years?
Learners, PR Template
Self checklist
Changelist
This PR completes the Sprint 4 Rental Summary Generator ticket.
RentalCalculatorinterface