Forum Stats

  • 3,825,999 Users
  • 2,260,586 Discussions


Lab 4 Solution

OTG-467455 Member Posts: 506 Bronze Badge
edited Dec 2, 2017 7:22AM in Java Puzzle Ball

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.



  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited Nov 29, 2017 3:11PM

    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.

  • OTG-467455
    OTG-467455 Member Posts: 506 Bronze Badge
    edited Nov 30, 2017 3:27AM

    Nick, Thank you. The lab solution was all that I was after.

  • OTG-467455
    OTG-467455 Member Posts: 506 Bronze Badge
    edited Nov 30, 2017 11:07AM

    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:

    1. Added two more predicates definitions in the ButtonController Class
      1. processSavingsAccount
      2. processCheckingAccount
    2. Changed the .filter parameters for
      1. button5Pressed and button6Pressed to substitute lambda expression with processSavingsAccount
      2. button7Pressed to substitute lambda expression with processCheckingAccount
    3. 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(){




    //Earn interest for each savings account.

        private void button6Pressed(){




    //Charge a $35 fee for each checking account with fewer than 1 transactions.

        private void button7Pressed(){



  • NickR2600-Oracle
    NickR2600-Oracle Member Posts: 530 Employee
    edited Dec 1, 2017 7:54PM

    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:

  • OTG-467455
    OTG-467455 Member Posts: 506 Bronze Badge
    edited Dec 2, 2017 7:22AM

    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.