Question
Explain this code in details in paragraph style. /* * To change this license header, choose License Headers in Project Properties. * To change this
Explain this code in details in paragraph style.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package orderhandler;
/**
*
* @author Muhammad.Adnan
*/
import java.io.IOException;
import java.nio.file.*;
import java.util.*;
import java.util.regex.Pattern;
public class OrderHandler {
private static final String FILENAME = "deliveryitem.txt";
List
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 ) {
orderLst.forEach((n) -> { System.out.println(n); });
}
//collect all orders and split them with '\'
List> collect(){
List> orderLst = new ArrayList();
data.forEach((i)->orderLst.add(Arrays.asList(i.split( Pattern.quote("\\") ))));
orderLst.removeIf(i->i.contains("PARCELITEM"));
return orderLst;
}
//compute the total payment of order placed
double computePaymnt( List> orderLst ) {
final double[] sum = {0};
orderLst.forEach((i)-> sum[0] +=Double.parseDouble(i.get(i.size()-1)));
return sum[0];
}
//export to order object comprises name and charges only
List> orderLst ){
List
orderLst.forEach((i)->items.add(new Item(i.get(0),i.get(i.size()-1))));
return items;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started