You are given the following Package class which has the abil

You are given the following Package class, which has the ability to create links for a linked list. Package represent a traditional box.

public class Package {
private double width, height, length; Package successor;
Package(Package p){

width=p.width; height=p.height; length=p.length;

}
Package(double w, double h, double l){

return width*height*length; }

}

You are given a Package linked list head as a parameter of a method. You are also given an independent Package object comparee as the second parameter. Construct a new linked list that contains Package objects with equal width, height, and length of the ones in the given linked list but whose volumes are greater than the volume of comparee. Return the head of the newly constructed linked list. You cannot change the given linked list in the process.

Solution

import java.util.*

class Package {

public int packageNum;

public int location; // 0 = flight, 1= truck, 2 = warehouse, 3 = delivered

public int siteId;

public GregorianCalendar entryDate;

public GregorianCalendar estDelivery;

public void computeCost();

};

class RegularPackage extends Package {

public double weight;

public int departureRegion;

public int destinationRegion;

public double cost;

public void computeCost() {

cost = 2*weight + 3*Math.abs(destinationRegion - departureRegion);

}

};

class ExpressPackage extends Package {

public int weightCategory;

public GregorianCalendar deliveryTime;

public double cost;

public void computeCost() {

cost = 12 + 5*weightCategory;

}

};

public class PackageUtilities {

public double getTotalCost(Package[] bundle) {

double totalCost = 0;

for (int i = 0; i < bundle.length; i++) {

bundle[i].computeCost();

totalCost += bundle[i].cost;

}

return totalCost;

}

public ArrayList<Package> getDeliveryPackages(Package[] bundle, GregorianCalendar delDate) {

ArrayList<Package> delivery = new ArrayList<Package>();

for (int i =0; i < bundle.length; i++) {

if ( delDate.get(Calendar.DATE) == bundle[i].estDelivery.get(Calendar.DATE)

&& delDate.get(Calendar.MONTH) == bundle[i].estDelivery.get(Calendar.MONTH)

&& delDate.get(Calendar.YEAR) == bundle[i].estDelivery.get(Calendar.YEAR) )

{

delivery.add(bundle[i]);

}

}

return delivery;

}

};

You are given the following Package class, which has the ability to create links for a linked list. Package represent a traditional box. public class Package {
You are given the following Package class, which has the ability to create links for a linked list. Package represent a traditional box. public class Package {

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site