Coder Social home page Coder Social logo

java-mod-4-lambda-expression-lab's Introduction

Lambda Expression Lab

Instruction

Do not create a new class. Use a lambda expression to implement the interface.

TASK #1:

Functional interface MyIntOperator defines an abstract method named apply:

@FunctionalInterface
public interface MyIntOperator {
    int apply(int x);
}

Task1.java declares a variable named nextInt and assigns the variable to null:

public static MyIntOperator nextInt = null ; //replace null with lambda expression

Edit Task1.java to replace the null value with a lambda expression that implements MyIntOperator. The lambda expression should increment the parameter by 1.

NOTE: The nextInt variable is defined as public static so the Junit test can access and test the lambda expression.

Run the program and confirm the output:

7
14
-4
1

Run the Junit test Task1Test to confirm your implementation.

TASK #2:

Functional interface MyIntPredicate defines abstract method test:

@FunctionalInterface
public interface MyIntPredicate {
    boolean test(int x);
}

Edit Task2.java to replace the null value with a lambda expression that implements MyIntPredicate.
The lambda expression should test whether the parameter is an even number.

public static MyIntPredicate isEven = null ; //replace null with lambda expression

Run the program and confirm the output:

true
false
false
true

Run the Junit test Task2Test to confirm your implementation.

TASK #3:

Edit Task3.java to replace the null value with a lambda expression that implements MyIntOperator.
The lambda expression should return the next odd number that follows the parameter value.

public static MyIntOperator nextOdd = null; //replace null with lambda expression

Run the program and confirm the output:

7
15
-3
1

Run the Junit test Task3Test to confirm your implementation.

java-mod-4-lambda-expression-lab's People

Contributors

alveem avatar linda-seiter avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.