Question: Read over Examples.java. It contains the examples from class and a few extras. 2 . Run the code and see if it executes as you
Read over Examples.java. It contains the examples from class and a few extras.
Run the code and see if it executes as you expect.
Fill in the blanks in Examplesjava
"Examples.java"
import java.util.function.;
class Examples
public static void mainString args
Predicate: Takes a single arguement and
returns a boolean
Predicate startsWithA s sstartsWithA;
System.out.printlnstartsWithAtesthello;
System.out.printlnstartsWithAtestapple;
System.out.printlnstartsWithAtestApple;
Predicate isEvenn n ;
System.out.printlnisEventest;
System.out.printlnisEventest;
Predicate isOddnisEven.testn;
System.out.printlnisOddtest;
System.out.printlnisOddtest;
Consumer: Represents an operation that accepts
a single input argument and returns no result
Consumer printConsumer sSystem.out.printlns;
printConsumer.accepthello;
Consumer printUppersSystem.out.printlnstoUpperCase;
printUpper.accepthello;
Consumer incrementnSystem.out.printlnn;
increment.accept;
Function: Represents a function that accepts
one argument and produces a result.
Function stringLength s slength;
System.out.printlnstringLengthapplyhello;
Function incrementnn;
System.out.printlnincrementapply;
int x;
xincrementapplyx;
System.out.printlnx;
Supplier: Represents a supplier of results
Supplier randomValue Math.random;
forint i;i;i
System.out.printlnrandomValueget;
"Examplesjava"
import java.util.function.;
import java.util.;
class Examples
public static void mainString args
Write a predicate for each of the following
To check if a list of strings is empty or not.
what type can you use so all the lines below
work?
Hint: Look at the Java heirarchy.
List strsArrays.asListhelloa"ABC";
Systemout.printlnpteststrs;
Systemout.printlnptestnew ArrayList;
Systemout.printlnptestnew LinkedList;
Check if a user is an admin or not.
Test by processing the whole queue
Queue usersnew LinkedList;
users.addnew Usermary"jane",;
users.addnew Userjohn"doe",;
users.addnew Userbarbara"jean",;
users.addnew Usermax"smith",;
Check if a users last name is at least characters long
Check if a users first name starts with ma
Check if an integer is between
Check if a users first name contains any charaters
that are not letters
Hint: use for multiple lines on the left hand side
of
Write a Consumer function for each
Multiply every integer of a list by
Hint: use for multiple lines on the left
hand side of the arrow
List valuesArrays.asList;
System.out.printlnvalues;
doubleListacceptvalues;
System.out.printlnvalues;
Reverse a list of integers
Write a supplier to generate a random int
in
Write a function for each
compute the square of a number
create an uppercase version of a string
gets the role of a user
generate a queue of users from a list
class User
private final String rolesadmin"student","staff","faculty";
private String first,last,role;
public UserString fString lint r
firstf;
lastl;
rolerolesr;
public String toString
return firstlastrole;
public String role
return role;
public String last
return last;
public String first
return first;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
