Menu

Next Day Cargo Company Needs Integrated Application System Sorts Cargo Respect Weight Dist Q43786215

Next Day Cargo Company needs an integrated application withtheir system that sorts the cargo with respect to their weight anddistributes the weight evenly (if possible) between the givenvehicles.

Note that each vehicle has a weight limit, and cannot exceed it.But each vehicle can be used more than once during theseoperations. And do not forget, they want a fast solution becausewaiting a long time for the algorithm to complete reports will risktheir motto, which is “Next Day Cargo”.

They require a report which will be used as a work order forworkers and truck drivers as it shows the order of load for eachvehicle. The report/order will have the following four columns:

Number (which will be the loading sequence), Barcode Number,Weight, Postal Code.

Our team has worked on API architecture and concluded in thesolution given in Figure 2.4. In this API there are two main steps,which are explained as follows;

  1. Sort the shipments: We are planning to use merge sort algorithm.Sorting must be from heaviest to lightest.

  2. Distribute the sorted shipments to vehicles: To distributeshipments to available vehicles there are some restriction/requestas follows;

    • There is a list of available vehicles, in which a vehicle can beused more than once if needed.

    • Total weight of assigned shipments to a vehicle cannot exceedits weight capacity.

    • Order of assignments must be from heaviest to lightest whichwill be used as a loading order.

Get Loading Array Sort Shipments by Weight Merge Sort wrt Weight Merge Distribute Shipments To Vehicles - - - Sort Shipments

Figure 2.4: Method Details

For the distribution of cargo to vehicles the following stepsare considered;

• Take each cargo in the given order,

• Take a vehicle and calculate the total weight of the takencargo assigned to the taken vehicle,

• If the capacity of the vehicle is not exceed, assign the cargoto the vehicle,

• If not, select another vehicle until a suitable vehicle isfound.

Vehicle and Shipment classes are completed in theAPI.LoadsOfVehicle and Sort classes need implementations.

A sample report is provided in the fileSampleReport.txt.

In order to sort the shipments by weight, you will need toimplement the sortShipmentsByWeight method in theSort.java file. To implement the sortShipmentsByWeight youwill need to implement the following two methodsmergeSortShipmentsByWeight and merge method.

mergeSortShipmentsByWeight will take three arguments, an arrayof shipments, a start index and an end index. This method shouldrecursively call itself until the shipment has been sorted.

The merge method should merge two halves of the sortedshipment.

Task

Develop the sortShipmentsByWeight() method in theSort.java file to sort cargo from heaviest tolightest.

2 The shipments now need to be distributed evenly among thevehicles. Each vehicle can do multiple transfers and can be usedmore than once if needed, but the weight limit of each vehiclecannot be exceeded.

The first method to implement is distributeShipmentsToVehicleswhich will return the maximum weight per load for each vehicle.Once the maximum capacity per vehicle has been calculated, theshipments need to be loaded onto the vehicle using theloadTheVehicles method.

Tasks

Develop the distributeShipmentsToVehicles method to evenlydistribute weight between transportation vehicles but do not exceedthe weight limit of each vehicle. (Each vehicle can do multipletransfers/can be used more than once if needed)

2 Implment the loadTheVehicles method to load the shipments intothe vehicles, the total capacity of the vehicles must be greaterthan the total weight of the shipment.

1 Implement the getLoadReport method in theLoadsOfVehicle.java file to generate a report.

2 Since the load reports will be read by humans and computersalike, it is important that the report format matches the samplereport, including spaces.

Our customer wants us to develop a new API for the daytimedelivery operations given in Figure 2.3. They want an algorithmthat will consider the weight of each shipment but this time theywant it to be loaded to the delivery truck in a sequence thatdriver can drive through the neighborhood. So simply they want theshipment to be sorted firstly by address and then the shipmentswill be sorted with respect to weight.

To achieve this, you can divide the shipments with respect totheir postal code. Since this operation will be done in a branchfirst 4 out 5 digits of the postal code will be same. The lastdigit will be different but close to each other for eachneighboring district, and the driver will drive in that order. Sofor each postal code, heavy shipments will be loaded first. And ofcourse, the last delivery must be first loaded to the vehicle (thereport should be in increasing or decreasing order with respect tothe postal code so that driver can use that order to travel betweenneighboring districts).

Briefly, an API will sort the shipments with respect to thepostal code, then for each postal code, it will sort them withrespect to the weight (from heaviest to lightest).

Below is the code given:

public class Sort {
  

   /**
   * @param shipments
   * @param vehicles
   * @return
   */
   public static LoadsOfVehicle[]getLoadingArray(Shipment[] shipments, Vehicle[] vehicles) {
                 
       return null;
   }
  

   /**
   * @param shipmentsToSort
   */
   public static void sortShipmentsByWeight(Shipment[]shipmentsToSort) {
             
   }  
  
/**
* @param shipmentsToSort
* @param start
* @param end
*/
private static void mergeSortShipmentsByWeight(Shipment[]shipmentsToSort, int start, int end) {
      
   }

   /**
   * @param array
   * @param start
   * @param middle
   * @param end
   */
   private static void merge(Shipment[] array, int start,int middle, int end) {
  
}

   /**
   * @param sortedShipments
   * @param vehicles
   * @return
   */
   public static LoadsOfVehicle[]distributeShipmentsToVehicles(
           Shipment[]sortedShipments, Vehicle[] vehicles) {
      
       //calculate total weight ofshipments

      
       //calculate total weight capacityof vehicles

      
       //if capacity of vehicles is notenough add more turns for vehicles

      
       //define return array with extravehicle turns

          
           //use modulus toadd vehicles more than once if needed

       //distribute weight tovehicles

      
       return null;
   }

   /**
   * @param vehicleListToLoad
   * @param sortedShipments
   */
   public static void loadTheVehicles(LoadsOfVehicle[]vehicleListToLoad, Shipment[] sortedShipments) {
                     
       //while there is more cargo toload
          
           //distributeweight over vehicles
             
              //calculate total weight if current weight isloaded
             
              //there is a cargo to load and vehicle has thecapacity
                 
                  //load cargo to vehicle
                 
                  //If no more cargo to loadbreak while loop
      
   }

   public static void main(String[] args) {
/*   
* This main method is a stub.
* It does nothing.
* Feel free to write your own code to test yourimplementation.
* In this case, we have nothing actionable in here, just thiscomment block, so the JVM should rapidly lose interest and move onto the rest of your code.
*/
}
  
}

Get Loading Array Sort Shipments by Weight Merge Sort wrt Weight Merge Distribute Shipments To Vehicles – – – Sort Shipments > Merge Sort – – Merge Sort – – > Merge Sorted – – Merge Sorted Merge – – Sorted Shipments Merged – – – Distribute the Cargo to Vehicles Distributed Cargo List – – – – – – – – – – – – – – – – – – – – – – – – – – – – – Show transcribed image text Get Loading Array Sort Shipments by Weight Merge Sort wrt Weight Merge Distribute Shipments To Vehicles – – – Sort Shipments > Merge Sort – – Merge Sort – – > Merge Sorted – – Merge Sorted Merge – – Sorted Shipments Merged – – – Distribute the Cargo to Vehicles Distributed Cargo List – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Expert Answer


Answer to Next Day Cargo Company needs an integrated application with their system that sorts the cargo with respect to their weig…

OR