Question: Core Java_Thread_Problem Statement 1 Cargos from multiple agents had arrived. The agents have provided each cargo's detail as a string in the following format <

Core Java_Thread_Problem Statement 1

Cargos from multiple agents had arrived. The agents have provided each cargo's detail as a string in the following format < Length, Width, Weight, Type >. For example, 2452,400,265,460,Non-Food,DRY 3345,170,455,350,FOOD,COLD Here type determines if the Cargo needs to be shipped in a Cold Storage container or a Dry storage container and each cargo has a different shipping cost as given below..,

Type of Storage Shipping Cost
Cold $1.85 / kg
Dry $0.90 / kg

Given the number of cargos and the cargo details, print the shipping cost for each cargo based on its weight and storage type using multiple threads. Create a class named Cargo with the following private members

Long id

Integer length

Integer width

Integer weight

String cargoType

String storageType

static String DRY_STORAGE

static String COLD_STORAGE

Include appropriate getters and setters and also include the following constructor in the Cargo class

Access specifier Constructor Purpose
public void Cargo(String s) Parametrized constructor that take a string argument. The contructor will the parse the string and assign values to the member variables

Create another class named ShippingCostThread that extends the Thread class with the following private member variables

List cargoList

List priceList

Include appropriate getters and setters. And include a method as follows

S.no Method name Method description
1 public void run() Override the run method, here you iterate the cargo list and calculate the shipping cost for each cargo and finally append the shipping cost of the corresponding cargo to the priceList

Any ith cargo in the cargoList will have its shipping cost in the ith index of priceList. Get inputs in the Main method

Parse the input string( cargo detail ) and create multiple cargo objects

Divide the Cargo detail list into two halves

Create two thread instances and pass the first half of the cargo list to 1st thread and the other half to 2nd thread and start the threads

Once both the threads are done calculating the prices of the cargos, print the price values from the price list of the threads.

[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.] Input Format The first line of input contains an integer n, the number of cargo details, The next n lines contains comma-seperated string that corresponds to the Cargo details, where each line contains one cargo's detail. Output Format The output is a list of double values, each cargo's price printed in a newline. Please refer to the sample input and output for more details. [All text in bold corresponds to input and the rest corresponds to output] Sample Input and Output Enter the number of Cargo: 4 Enter cargo details (id,length,width,weight,cargo type,storage type): 1556,200,250,150,Food,DRY 2452,400,265,460,Non-Food,DRY 3345,170,455,350,FOOD,COLD 4845,120,100,250,FOOD,COLD Price List: 135.0 414.0 647.5 462.5

I am providing the piece of Code. Please complete it accordigly based on the problem statement and send me back.

Cargo.Java

public class Cargo {

private Long id; private Integer length; private Integer width; private Integer weight; private String cargoType; private String storageType; //Dry Storage or Cold Storage

public static String DRY_STORAGE = "DRY"; public static String COLD_STORAGE = "COLD"; public Cargo(String value) { String val[] = value.split(","); id = Long.parseLong(val[0]); length = Integer.parseInt(val[1]); width = Integer.parseInt(val[2]); weight = Integer.parseInt(val[3]); cargoType = val[4]; storageType = val[5]; } public Long getId() { return id; }

public void setId(Long id) { this.id = id; }

public Integer getLength() { return length; }

public void setLength(Integer length) { this.length = length; }

public Integer getWidth() { return width; }

public void setWidth(Integer width) { this.width = width; }

public Integer getWeight() { return weight; }

public void setWeight(Integer weight) { this.weight = weight; }

public String getCargoType() { return cargoType; }

public void setCargoType(String cargoType) { this.cargoType = cargoType; }

public String getStorageType() { return storageType; }

public void setStorageType(String storageType) { this.storageType = storageType; } }

ShippingCostThread.Java

import java.util.ArrayList; import java.util.Iterator; import java.util.List;

public class ShippingCostThread //fill in your code {

public void run() { //fill in your code here }

public List getCargoList() { return cargoList; }

public void setCargoList(List cargoList) { this.cargoList = cargoList; }

public List getPriceList() { return priceList; }

public void setPriceList(List priceList) { this.priceList = priceList; } }

Main.Java

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List;

public class Main { public static void main(String args[]) throws IOException, InterruptedException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the number of Cargo:"); int numberOfCargo = Integer.parseInt(reader.readLine()); System.out.println("Enter cargo details (id,length,width,weight,cargo type,storage type):"); List cargoList = new ArrayList(); for(int i=0;i list) { //fill in your code } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!