Question: TASK 2: Analyse the following Java code in Figure 1 and 2. Rewrite the given program code using logic programming paradigm, Prolog. Your solution should
TASK 2: Analyse the following Java code in Figure 1 and 2. Rewrite the given program code using logic programming paradigm, Prolog. Your solution should include recursive concept and demonstrate the query sample. Part 1: import java.util. import java.util.stream.Collectors; public class Filter { public static List Number> apply List Number> Ist, Double target){ return ist.strean() .mapToDoublel Number::doublevalue) .filteri elem -> elem > target) .boxed() collecti Collectors.toCollection ArrayList:: new ) ); } public static void main(String[] args) { // Integer (1 nums = new Integer () {1,2,3,4,5,6,7,8,9); Doublell nums = new Doublell (2.1,3.2.4.3,5.4,6.5,7.6,8.7): System.out.println Filter.apply( Arrays.asList(nums), 5.0 ) 3 Figure 1: Filter the numeric elements based on target value Part 2: import java.util.*; import java.util.stream.*; public class Demo public static void main(String!] args) { String) 1 Ist = { }; Stream String[]> strean = Arrays.strean(Ist); System.out.println( stream . flatMap arr -> Arrays.stream(arr)) collecti Collectors.toCollection Linkedlist:: new ) ) Figure 2: Joining the elements from the array objects as a collection of objects
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
