Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 439 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Lab 4 Solution

Hi Nick, I have completed the course and notice that there is on solution posted for Lab 4. Could I ask you to post the solution once the course is terminated. That is past the deadline date.
Also please let me have any answers or feedback you have been able to get from your colleagues for the questions I have posted.
Answers
-
Hi OTG, Congrats on finishing! I've just posted the solution for Lab 4. You'll still be able to access most of the course materials after the course officially ends. The only thing that'll be inaccessible after December 6 are the quizzes.
Yes, I'll give my colleagues another poke.
-
Nick, Thank you. The lab solution was all that I was after.
-
Hi Nick, I performed a diff using NetBeans and found that I went a little bit further with my code and would like to hear your comments on what I did.
In the lab instructions you encourage us to venture a bit further if we would like to do so and also where code is repeated more than once to try use Lambda expressions to reduce code duplication.
I did the following:
- Added two more predicates definitions in the ButtonController Class
- processSavingsAccount
- processCheckingAccount
- Changed the .filter parameters for
- button5Pressed and button6Pressed to substitute lambda expression with processSavingsAccount
- button7Pressed to substitute lambda expression with processCheckingAccount
- The only other difference is that I left the code to print "DETAILS" inside the .forEach loop in the button1Pressed method.
The code snippets:
Now that the lab is available for all, here is my code implementation.
public class ButtonController {
ArrayList<Account> accountList = new ArrayList<>();
TextField ownerSearchBar;
TextField numberSearchBar;
~~~~~~~~
Predicate<Account> matchAccountOwner = (a -> a.getAccountOwner().equals(ownerSearchBar.getText())); //Replace null
Predicate<Account> matchAccountNumber = (a -> String.valueOf(a.getAccountNumber()).equals(numberSearchBar.getText())); //Replace null
Predicate<Account> processSavingsAccount = (a -> a.getAccountType().equals("Savings Account"));
Predicate<Account> processCheckingAccount = (a -> a.getAccountType().equals("Checking Account"));
~~~~~~~~~~~~~~~~~~~~~
//Deposit a bonus $20 for each savings account with a balance of at least $20,000.
private void button5Pressed(){
accountList.stream()
.filter(processSavingsAccount)
~~~~~~~~~~~~~~~~~~~~~
//Earn interest for each savings account.
private void button6Pressed(){
accountList.stream()
.filter(processSavingsAccount)
~~~~~~~~~~~~~~~~~~~~~
//Charge a $35 fee for each checking account with fewer than 1 transactions.
private void button7Pressed(){
accountList.stream()
.filter(processCheckingAccount)
- Added two more predicates definitions in the ButtonController Class
-
Indeed. I wanted to call out and encourage this way of thinking because I wasn't sure how well the game conveyed the idea of "functional programming".
Those clever solutions you've found hadn't occurred to me. I'm glad you're enjoying the exercise because a major goal with the game-based learning approach was to empower developers to feel confident and curious about exploring code solutions. In the long run, the reduction in duplication should help make the code more maintainable. Especially if the program needs to grow and perform additional checks to verify accounts.
There's a course JDK 8: Lambda and Streams Introduction that you may be interested in as a follow up. The course goes very much in depth on lambdas and functional programming. We originally delivered the course as a MOOC, and recently converted it to a self-paced Learning Path (a lot like a MOOC, but without quizzes or forum support). It can be found here: https://www.oracle.com/goto/LearningPaths.
-
Thanks, Mick. We seem to think alike. I have been watching those videos since the start of the PuzzleBall MOOC as well as your course content. It is approximately 186 minutes of videos.