One of my favorite projects so far. Learn how to reuse code and expand for new features. The Validator has a mercy here too.
Justin SmithLevel 41, Greenfield, USA, United States
13 February 2023
I keep coming back to edit this as I progress through the task.
This is one of my favorite big tasks so far. Really good project for learning to optimize your code efficiency. After part 1 I had almost 400 lines of code. It was super bloated. After part 2, I have... almost 400 lines of code, despite more than doubling the number of methods.
In between (and I recommend you do this, too), I read up on how to use Java lambdas, and how they work with collection filtering. I think CodeGym doesn't go into lambdas because they were introduced with Java 8 and CG was developed for Java 7 originally.
Anyway, as a learning experience I recommend just go through Part 1 and see how much redundant code you end up with, and then with part 2, scrap the whole thing and think strategically about how to compress the redundant code into only being called once. Ideally, you want a single method that handles all the filtering of the collection, and the methods that are required for the tasks just call that central method with appropriate parameters to get what they need.
I suggest creating an Enum for the data type that you want to filter by or return.
If you create a flexible query method by the end of Part 2, then Parts 3 & 4 become Easy tasks!
This task is a great example of how I wish we had a place to discuss our own solutions, I'm really pleased with mine!
GO TO FULL VERSION