Question: All the instructions are within the code. import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; public class lab4 { /** * Run the

All the instructions are within the code.

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

import java.util.Map;

import java.util.TreeMap;

public class lab4 {

/**

* Run the exercises to ensure we got the right answers

*/

public void runExercises() {

System.out.println("Running exercise 1 solution...");

exercise1();

System.out.println("Running exercise 2 solution...");

exercise2();

System.out.println("Running exercise 3 solution...");

exercise3();

System.out.println("Running exercise 4 solution...");

exercise4();

}

/**

* All exercises should be completed using Lambda expressions and the new

* methods added to JDK 8 where appropriate. Use method references rather than full

* lambda expressions wherever possible.

* Implement interfaces for each of your lambda functions and show that you can run them from a tester class

*/

/**

* Exercise 1

*

* A string needs to be created that consists of the first letter of each word in the

* list of Strings provided.

*/

private void exercise1() {

List list = Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot");

// Write code in these empty lines

}

/**

* Exercise 2

*

* Remove the words that have even lengths from the list.

*/

private void exercise2() {

List list = new ArrayList<>(Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot"));

// Write code in these empty lines

}

/**

* Exercise 3

*

* Replace every word in the list with its upper case equivalent.

*/

private void exercise3() {

List list = new ArrayList<>(Arrays.asList("alpha", "bravo", "charlie", "delta", "echo", "foxtrot"));

// Write code in these empty lines

}

/**

* Exercise 4

*

* Convert every key-value pair of the map into a string and append them all

* into a single string, in iteration order.

*/

private void exercise4() {

Map map = new TreeMap<>();

map.put("c", 3);

map.put("b", 2);

map.put("a", 1);

// Write code in these empty lines

}

/**

* Main entry point for application

*

* @param args

* the command line arguments

*/

public static void main(String[] args) {

lab4 lab = new lab4();

lab.runExercises();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!