Question: Core Java_Thread_Problem Statement 2 All the shipments are ready to be shipped to the carrier. The carrier needs the shipment details in a defined format.,
Core Java_Thread_Problem Statement 2
All the shipments are ready to be shipped to the carrier. The carrier needs the shipment details in a defined format., i.e their details should be seperated by pipe symbol. Since the system needs to handle large volumes (more than 1 lakh) of shipment everyday, to reduce the processing time the automation is implemented using multi-threading. Sample Format id | name | booking number | executed place | executed date | departure date | arrival date | total weight | shipment status | carrier id For example, 2390900|Agro Ltd|88412525|Mumbai|2017/05/16|2017/05/16||7500|10|41004500 2391990|Tumac Commodities|88425455|Mumbai|2017/05/14|2017/05/16||7500|10|41004500 Given the number of threads, print the shipment details in the above prescribed format using multiple threads. Create a class named Shipment with the following private member variables
Long id
String name
Long bookingNumber
String executedPlace
Date executedDate
Date departureDate
Date storageType
Date arrivalDate
Integer totalWeight
Integer shipmentStatus
Integer carrierId
Include appropriate getters and setters. And include a parametrized constructor with argument order ( Long id,String name,Long bookingNumber,String executedPlace,Date executedDate,Date departureDate,Date arrivalDate,Integer totalWeight,Integer shipmentStatus,Integer carrierId) Create another class named ExportShipmentThread that extends the Thread class with the following private member variables
List
StringBuilder shipmentDetails
Include appropriate getters and setters. And include a parametrized constructor with argument order (List
| s.no | Method name | Method Description |
| 1 | public void run() | Override the run method, here you iterate the shipment list and construct the detail in the prescribed format and assign it to shipmentDetails |
Predefine all the shipments in an array of objects in your Main class
Read n, the number of threads to process the data
Divide the shipment list into equal halves depending on n,the number of threads.
Create n thread instances in the main class and pass the shipment list corresponding to each thread and start the threads, where it should construct the carrier data seperated by pipe symbol
Wait for all the thread to complete the processing and then print the output string from all the threads
Hint Please follow the dd/MM/yyyy date format when using SimpleDataFormat class for formatting the date in the output. Input Format The first line of input contains an integer n, the number of threads. Output Format The output contains list of strings, shipment details seperated by | symbol. Where each shipment details is printed in a new line. Please refer to the sample input and output for more details. [Note :Strictly adhere to the object oriented specifications given as a part of the problem statement.Use the same class names, attribute names and method names.] [All text in bold corresponds to input and the rest corresponds to output] Sample Input and Output Enter number of threads to process the data: 2 Shipping Details: 2390900|Agro Ltd|88412525|Mumbai|2017/05/16|||7500|10|41004500 2391990|Tumac Commodities|88425455|Mumbai|2017/05/14|||7500|10|41004500 2356000|HAKAN AGRO|88412522|Mumbai|2017/05/12|||7500|10|41004500 2366785|BTW|88415522|Mumbai|2017/05/14|||7500|10|41004500 2366854|Bisk Farm|86555520|Mumbai|2017/05/16|||7500|10|41004500 2398222|Meat Products of India|88785545|Mumbai|2017/05/16|||7500|10|41004500 2389452|Balaji Group|88123455|Mumbai|2017/05/16|||7500|10|41004500 2352000|Agro Ltd|88412785|Mumbai|2017/05/13|||7500|10|41004500 2394566|Heritage Foods|88412563|Mumbai|2017/05/15|||7500|10|41004500 237800|ITC|88452678|Mumbai|2017/05/16|||7500|10|41004500
Here I am providing the piece of Code. Please update it accordingly based on the problem statement and send me back. This program should run as per the input and output conditions:
ExportShipmentThread.Java
import java.text.SimpleDateFormat; import java.util.Iterator; import java.util.List;
public class ExportShipmentThread //fill in your code here {
//fill in your attributes
public ExportShipmentThread(List
Shipment.Java
import java.util.Date;
public class Shipment {
private Long id; private String name; private Long bookingNumber; private String executedPlace; private Date executedDate; private Date departureDate; private Date arrivalDate; private Integer totalWeight; private Integer shipmentStatus; private Integer carrierId;
public Shipment(Long id,String name,Long bookingNumber,String executedPlace,Date executedDate,Date departureDate,Date arrivalDate,Integer totalWeight,Integer shipmentStatus,Integer carrierId) { this.id = id; this.name = name; this.bookingNumber = bookingNumber; this.executedPlace = executedPlace; this.executedDate = executedDate; this.arrivalDate = arrivalDate; this.totalWeight = totalWeight; this.shipmentStatus = shipmentStatus; this.carrierId = carrierId; } public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public Long getBookingNumber() { return bookingNumber; }
public void setBookingNumber(Long bookingNumber) { this.bookingNumber = bookingNumber; }
public String getExecutedPlace() { return executedPlace; }
public void setExecutedPlace(String executedPlace) { this.executedPlace = executedPlace; }
public Date getExecutedDate() { return executedDate; }
public void setExecutedDate(Date executedDate) { this.executedDate = executedDate; }
public Date getDepartureDate() { return departureDate; }
public void setDepartureDate(Date departureDate) { this.departureDate = departureDate; }
public Date getArrivalDate() { return arrivalDate; }
public void setArrivalDate(Date arrivalDate) { this.arrivalDate = arrivalDate; }
public Integer getTotalWeight() { return totalWeight; }
public void setTotalWeight(Integer totalWeight) { this.totalWeight = totalWeight; }
public Integer getShipmentStatus() { return shipmentStatus; }
public void setShipmentStatus(Integer shipmentStatus) { this.shipmentStatus = shipmentStatus; }
public Integer getCarrierId() { return carrierId; }
public void setCarrierId(Integer carrierId) { this.carrierId = carrierId; } }
Main.Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String args[]) throws IOException, InterruptedException, ParseException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
List
shipmentList.add(new Shipment(2390900L,"Agro Ltd",88412525L,"Mumbai",sdf.parse("16/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2391990L,"Tumac Commodities",88425455L,"Mumbai",sdf.parse("14/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2356000L,"HAKAN AGRO",88412522L,"Mumbai",sdf.parse("12/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2366785L,"BTW",88415522L,"Mumbai",sdf.parse("14/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2366854L,"Bisk Farm",86555520L,"Mumbai",sdf.parse("16/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2398222L,"Meat Products of India",88785545L,"Mumbai",sdf.parse("16/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2389452L,"Balaji Group",88123455L,"Mumbai",sdf.parse("16/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2352000L,"Agro Ltd",88412785L,"Mumbai",sdf.parse("13/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(2394566L,"Heritage Foods",88412563L,"Mumbai",sdf.parse("15/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
shipmentList.add(new Shipment(237800L,"ITC",88452678L,"Mumbai",sdf.parse("16/05/2017"),sdf.parse("16/05/2017"),null,7500,10,41004500));
System.out.println("Enter number of threads to process the data:");
int numberOfThreads = Integer.parseInt(reader.readLine());
//fill in your code heres
}
public static void displayPrice(List
//fill in your code here
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
