Repository navigation
London | 26-Java-June | Shaghayegh far | Sprint 4 | Car rental generator - #58
shaghayeghfar wants to merge 1 commit into
Conversation
jwjlord
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Would be useful to have Javadoc on this interface and its method
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public class Contract { |
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public class Rental { |
| public boolean isPaid() { | ||
| return paid; | ||
| } | ||
|
|
There was a problem hiding this comment.
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 { |
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| Contract contract = new Contract( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ThreeYearsContractRentalGenerator implements RentalCalculator { |
| totalCapital += rental.getCapitalAmount(); | ||
| totalInterest += rental.getInterestAmount(); | ||
|
|
||
| if (!rental.isPaid()) { |
There was a problem hiding this comment.
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.
Learners, PR Template
Self checklist
I Implemented the Rental Summary Generator with contract validation, rental generation for 1 and 3-year contracts.