Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve this 2 task java language task 1 task 2 OVERVIEW Programming paradigms can be defined as programming styles in problem solving. In software programing

solve this 2 task java language
task 1 image text in transcribed
image text in transcribed
image text in transcribed
task 2
image text in transcribed
OVERVIEW Programming paradigms can be defined as programming styles in problem solving. In software programing languages, there are distinct programming paradigms and a set of programming concepts used in the platforms. In practice, imperative programming like procedural or object-oriented paradigms are widely used in various programming platforms. Likewise, the declarative programming such as functional programming and logic programming paradigms can also be available in modem programming languages. In this assignment, therefore, focuses on programming paradigms primarily imperative and declarative programming paradigms for a specific problem solving REQUIREMENTS Given the following computing solution code in Task 1 and Task 2. They are mostly implemented imperatively so you are required to test the program to understand how it works and rewrite them using declarative programming approach. TASK 1: Consider the following order information in the given file. Filename: deliveryitem.txt. PARCELITOINT DELIVERYTIME RECIPIENT POSTINGADORS CONTACT CASE PIZTAUTSARA 12:00 ATSTEPHENAU AT TIM329.90 KICHOCANTHOSISREPETALING30991888139.98 MACDONALNA KRAV: MICKEY SETAPAK U2347434343159.00 GROENCHOPERATION COMBUKIT JALIL 187707_2.0 STEAK SARANDE CELU SERW03222223327125.00 Analyse the imperative program code as shown in Listing 1. Adapt cach of the programming methods using functional programming concepts. Your solution code should consider higher-order function, method references, functional interfaces or lambda expression, function pipelining, nullable object, collection of objects and etc. Listing 1 Imperative programing paradigm - code sample: import java.io.IOException; import java.nio.file.*; import java.util.*; import java.util. regex.Pattern; public class OrderHandler { private static final String FILENAME = "data/deliveryitem.txt"; List data; public OrderHandler() { try { data = Files.readAllLines if data = Files.readAllLines Paths.get( FILENAME ) ); } catch (IOException e) { e.printStackTrace(); } } //display all order information except the heading text void print List> orderlst) { for (int i = 0; i> collect(){ List> orderLst = new ArrayList(); for (int i = 0; i > orderlst) { double sum = 0; for (int i = 0; i populatel List populated List> orderLst ) { List items = new ArrayList(); for (int i = 0; i apply List Number Ist, Double target){ return ist.strean() . mapToDoublel Number::doublevalue) .filtert elem -> elem > target) .boxed() .collect Collectors.toCollection ArrayList:new ) ); } public static void main(String[] args) { // Integer ll nums = new Integer ] {1,2,3,4,5,6,7,8,9); Double() 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 } } 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 11) Ist = { }; Strean stream = Arrays.strean(Ist); System.out.println( stream .flatMapl arr -> Arrays.strean(arr)) .collect Collectors.toCollection LinkedList:: new ) ) ): Figure 2: Joining the elements from the array objects as a collection of objects OVERVIEW Programming paradigms can be defined as programming styles in problem solving. In software programing languages, there are distinct programming paradigms and a set of programming concepts used in the platforms. In practice, imperative programming like procedural or object-oriented paradigms are widely used in various programming platforms. Likewise, the declarative programming such as functional programming and logic programming paradigms can also be available in modem programming languages. In this assignment, therefore, focuses on programming paradigms primarily imperative and declarative programming paradigms for a specific problem solving REQUIREMENTS Given the following computing solution code in Task 1 and Task 2. They are mostly implemented imperatively so you are required to test the program to understand how it works and rewrite them using declarative programming approach. TASK 1: Consider the following order information in the given file. Filename: deliveryitem.txt. PARCELITOINT DELIVERYTIME RECIPIENT POSTINGADORS CONTACT CASE PIZTAUTSARA 12:00 ATSTEPHENAU AT TIM329.90 KICHOCANTHOSISREPETALING30991888139.98 MACDONALNA KRAV: MICKEY SETAPAK U2347434343159.00 GROENCHOPERATION COMBUKIT JALIL 187707_2.0 STEAK SARANDE CELU SERW03222223327125.00 Analyse the imperative program code as shown in Listing 1. Adapt cach of the programming methods using functional programming concepts. Your solution code should consider higher-order function, method references, functional interfaces or lambda expression, function pipelining, nullable object, collection of objects and etc. Listing 1 Imperative programing paradigm - code sample: import java.io.IOException; import java.nio.file.*; import java.util.*; import java.util. regex.Pattern; public class OrderHandler { private static final String FILENAME = "data/deliveryitem.txt"; List data; public OrderHandler() { try { data = Files.readAllLines if data = Files.readAllLines Paths.get( FILENAME ) ); } catch (IOException e) { e.printStackTrace(); } } //display all order information except the heading text void print List> orderlst) { for (int i = 0; i> collect(){ List> orderLst = new ArrayList(); for (int i = 0; i > orderlst) { double sum = 0; for (int i = 0; i populatel List populated List> orderLst ) { List items = new ArrayList(); for (int i = 0; i apply List Number Ist, Double target){ return ist.strean() . mapToDoublel Number::doublevalue) .filtert elem -> elem > target) .boxed() .collect Collectors.toCollection ArrayList:new ) ); } public static void main(String[] args) { // Integer ll nums = new Integer ] {1,2,3,4,5,6,7,8,9); Double() 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 } } 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 11) Ist = { }; Strean stream = Arrays.strean(Ist); System.out.println( stream .flatMapl arr -> Arrays.strean(arr)) .collect 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is Medicare? Describe Parts A and B of Medicare.

Answered: 1 week ago

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago