Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

}

//find and display all order item names

List display( List> orderLst ) {

List name = new ArrayList();

for (List list : orderLst) {

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

}

}

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

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago