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  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( 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 < orderLst.size(); i++) {                                              System.out.println( orderLst.get(i) );                               }                }                //collect all orders and split them with '\'                List> collect(){                               List> 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> 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 populate( List> orderLst ){                               List 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;                } }

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

Things i want is in picture attached

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 

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<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;

               }

}

 

Solution code
print) - Display all order inform ation from the given file.
collect() - Filter the heading text, collect all order records and split
them using a character of ' into a list of collections.
compute Payment)- Compute the total of payment for all orders.
ponulate()- Obtain order item name and price only and store them in
Item objects.
Transcribed Image Text:Solution code print) - Display all order inform ation from the given file. collect() - Filter the heading text, collect all order records and split them using a character of ' into a list of collections. compute Payment)- Compute the total of payment for all orders. ponulate()- Obtain order item name and price only and store them in Item objects.
Expert Solution
trending now

Trending now

This is a popular 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