tel-ran-de / BE10-Basic

Basic Java Group 10
1 stars 8 forks source link

HW 2020-06-04 Functional interfaces with lambda expressions #27

Open sergeylukichev opened 4 years ago

sergeylukichev commented 4 years ago

Using lambda expressions, implement functional interfaces.

Sample: return a length of the string, "abc" -> 3, solution: Function<String, Integer> f = s -> s.length();

  1. Given an integer, return a power of integer: 5 -> 25
  2. Given a string, return modulo 2 of string length: "abcde" -> 1
  3. Given a string, return its in upper case: "ivan" -> "IVAN"
  4. Given 2 strings, return a sum of their lengths: "abc", "de" -> 5
  5. Given 2 strings, print a sum of their lengths.
  6. Return a date of one week prior to today: "2020-05-30"
  7. Given a string, return a string, which consists of a first half of its character, if length is even, returns an empty string otherwise: "abcde" -> "ab", "abcde" -> "".
  8. Return a random number
  9. Given a string, return a reversed string: "abc" ->"cba"
  10. Given a number, return a reversed number: 12345 -> 54321
  11. Given a number, return true if it is even, false otherwise: 6 -> true, 25 -> false
  12. Given a string, return true, if its length is more than 3, false otherwise: "ab" -> false, "abc" -> true
  13. Given a string and a number x. Return true, if length of string is more than x, false otherwise. Hint: BiPredicate.

Using method reference, implement functional interfaces:

  1. Print a given string
  2. Given a string, return a lower case string
  3. Given a number, return a square root from the number
  4. Implement solution 7 from above as a method reference
  5. Given a class Employee with name and salary. Return an employee salary using 1. Supplier, 2. Function.