Question
can you please explain this code in detail in paragraph style thank you. package labtestforUC3F2005; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays;
can you please explain this code in detail in paragraph style thank you.
package labtestforUC3F2005;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
public class OrderHandler {
private static final String FILENAME = "data/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 ) {
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;
}
//find and display all order item names
List> orderLst ) {
List
for (List
name.add( list.get(0) );
}
return name;
}
//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> orderLst ){
List
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;
}
}
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