Analyse the imperative program code as shown in Listing 1. Adapt each 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Analyse the imperative program code as shown in Listing 1. Adapt each 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/delivery item.txt";
List<String> data;
public OrderHandler() {
try {
}
data = Files. readAllLines ( Paths.get( FILENAME ) );
} catch (IOException e) {
e.printStackTrace();
}
//display all order information except the heading text
void print List<List<String>> orderLst ) {
for (int i = 0; i < orderLst.size(); i++) {
System.out.println( orderLst.get(i));
}
}
//collect all orders and split them with '\'
List<List<String>> collect() {
List<List<String>> orderLst = new ArrayList();
for (int i = 0; i < data.size(); i++) {
}
if(!data.get(i).startsWith("PARCELITEM")) {
String[] split = data.get(i).split( Pattern.quote("\\")
orderLst.add( Arrays.asList( split ) );
}
}
return orderLst;
}
//compute the total payment of order placed
double computePaymnt ( List<List<String>> orderLst ) {
double sum = 0;
for (int i = 0; i < orderLst.size(); i++) {
int count
orderLst.get(i).size();
double charge = Double.parseDouble( orderLst.get(i).get(count-1
sum + charge;
}
return sum;
}
//export to order object comprises name and charges only
List<Item> populate( List<List<String>> orderLst ) {
List<Item> items = new ArrayList();
for (int i = 0; i < orderLst.size(); i++) {
int count
orderLst.get(i).size();
String first = orderLst.get(i).get(0);
String last = orderLst.get(i).get(count-1);
items.add(new Item( first, last));
}
return items;
Transcribed Image Text: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/delivery item.txt"; List<String> data; public OrderHandler() { try { } data = Files. readAllLines ( Paths.get( FILENAME ) ); } catch (IOException e) { e.printStackTrace(); } //display all order information except the heading text void print List<List<String>> orderLst ) { for (int i = 0; i < orderLst.size(); i++) { System.out.println( orderLst.get(i)); } } //collect all orders and split them with '\' List<List<String>> collect() { List<List<String>> orderLst = new ArrayList(); for (int i = 0; i < data.size(); i++) { } if(!data.get(i).startsWith("PARCELITEM")) { String[] split = data.get(i).split( Pattern.quote("\\") orderLst.add( Arrays.asList( split ) ); } } return orderLst; } //compute the total payment of order placed double computePaymnt ( List<List<String>> orderLst ) { double sum = 0; for (int i = 0; i < orderLst.size(); i++) { int count orderLst.get(i).size(); double charge = Double.parseDouble( orderLst.get(i).get(count-1 sum + charge; } return sum; } //export to order object comprises name and charges only List<Item> populate( List<List<String>> orderLst ) { List<Item> items = new ArrayList(); for (int i = 0; i < orderLst.size(); i++) { int count orderLst.get(i).size(); String first = orderLst.get(i).get(0); String last = orderLst.get(i).get(count-1); items.add(new Item( first, last)); } return items;
PARCELITEM\WEIGHT\DELIVERYTIME\RECIPIENT\POSTINGADDR\CONTACT\CASH
PIZZAHUT\500GRAM\12:00PM\STEPHEN\APU AT TPM\0389900000\29.90
KFC\400GRAM\2:00PM\THOMAS\SRIPETALING\038998888\59.90
MACDONAL\300GRAM\8:00PM\MICKEY\SETAPAK\0341414141\59.80
CHICKKENCHOP\250GRAM\7:30PM\JOHNSON\BUKITJALIL\0387878787\19.80
STEAK\150GRAM\8:30PM\HELEN\SERDANG\0322223333\29.80
Transcribed Image Text:PARCELITEM\WEIGHT\DELIVERYTIME\RECIPIENT\POSTINGADDR\CONTACT\CASH PIZZAHUT\500GRAM\12:00PM\STEPHEN\APU AT TPM\0389900000\29.90 KFC\400GRAM\2:00PM\THOMAS\SRIPETALING\038998888\59.90 MACDONAL\300GRAM\8:00PM\MICKEY\SETAPAK\0341414141\59.80 CHICKKENCHOP\250GRAM\7:30PM\JOHNSON\BUKITJALIL\0387878787\19.80 STEAK\150GRAM\8:30PM\HELEN\SERDANG\0322223333\29.80
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY