Menu
support@authoritypapers.com
+1(805) 568 7317

package delivery services such as fedex dhl and ups offer a number of different ship 5188760

Package-delivery services, such as FedEx, DHL and UPS, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use Package as the base class of the hierarchy. Then add two classes, TwoDayPackage and OvernightPackage, that are derived from Package. Base class Package should include private instance variables representing the name and address for the package’s sender and recipient, and instance variables that store the weight (in ounces) and cost per ounce to ship the package. Create public properties for these instance variables. Package’s constructor should have six parameters: sender’s name, sender’s address, recipient’s name, recipient’s address, weight and cost per ounce. It should initialize the private instance variables with public properties. Ensure that the weight and cost per ounce contain non-negative values. Package should provide a public method CalculateCost that returns a decimal indicating the cost associated with shipping the package. Package’s CalculateCost method should determine the cost by multiplying the weight by the cost per ounce. Derived class TwoDayPackage should inherit the functionality of base class Package, but also include a private instance variable (and corresponding public property) that represents a flat fee the shipping company charges for two-day delivery service. TwoDayPackage’s constructor should have an additional parameter for this flat fee. This class should redefine method CalculateCost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class’s CalculateCost method. Class OvernightPackage should inherit directly from class Package and contain a private instance variable (and corresponding public property) representing an additional fee per ounce charged for overnight delivery service. OvernightPackage’s constructor should have an additional parameter for this additional fee per ounce. This class should redefine method CalculateCost so that it adds the additional fee per ounce to the standard cost per ounce when calculating the shipping cost.

Use the following TestPackages class to test your code.

class TestPackages

{

    static void Main(string[] args)

    {

        Package regularPackage = new Package(“Peter Anderson”, “123 Main St, Ashville, NC 27111”, “Mary Brown”, “456 Broad St, Benson, NC 27222”, 14, 0.5M);

        Console.WriteLine(“nRegular Package: “);

        Console.WriteLine(”  Sender's Name: {0}”, regularPackage.SenderName);

        Console.WriteLine(”  Sender's Address: {0}”, regularPackage.SenderAddress);

        Console.WriteLine(”  Recipient's Name: {0}”, regularPackage.RecipName);

        Console.WriteLine(”  Recipient's Address: {0}”, regularPackage.RecipAddress);

        Console.WriteLine(”  Weight: {0}”, regularPackage.Weight);

        Console.WriteLine(”  Cost Per Ounce: {0:C}”, regularPackage.CostPerOunce);

        Console.WriteLine(”  Shipping Cost: {0:C}”, regularPackage.CalculateCost());

        TwoDayPackage twoDayPackage = new TwoDayPackage(“Peter Anderson”, “123 Main St, Ashville, NC 27111”, “Mary Brown”, “456 Broad St, Benson, NC 27222”, 14, 0.5M, 4M);

        Console.WriteLine(“nTwo-Day Package: “);

        Console.WriteLine(”  Sender's Name: {0}”, twoDayPackage.SenderName);

        Console.WriteLine(”  Sender's Address: {0}”, twoDayPackage.SenderAddress);

        Console.WriteLine(”  Recipient's Name: {0}”, twoDayPackage.RecipName);

        Console.WriteLine(”  Recipient's Address: {0}”, twoDayPackage.RecipAddress);

        Console.WriteLine(”  Weight: {0}”, twoDayPackage.Weight);

        Console.WriteLine(”  Cost Per Ounce: {0:C}”, twoDayPackage.CostPerOunce);

        Console.WriteLine(”  Flat Fee: {0:C}”, twoDayPackage.FlatFee);

        Console.WriteLine(”  Shipping Cost: {0:C}”, twoDayPackage.CalculateCost());

        OvernightPackage overnightPackage = new OvernightPackage(“Peter Anderson”, “123 Main St, Ashville, NC 27111”, “Mary Brown”, “456 Broad St, Benson, NC 27222”, 14, 0.5M, 0.8M);

        Console.WriteLine(“nOvernight Package: “);

        Console.WriteLine(”  Sender's Name: {0}”, overnightPackage.SenderName);

        Console.WriteLine(”  Sender's Address: {0}”, overnightPackage.SenderAddress);

        Console.WriteLine(”  Recipient's Name: {0}”, overnightPackage.RecipName);

        Console.WriteLine(”  Recipient's Address: {0}”, overnightPackage.RecipAddress);

        Console.WriteLine(”  Weight: {0}”, overnightPackage.Weight);

        Console.WriteLine(”  Cost Per Ounce: {0:C}”, overnightPackage.CostPerOunce);

        Console.WriteLine(”  Additional Cost Per Ounce: {0:C}”, overnightPackage.AddFeePerOunce);

        Console.WriteLine(”  Shipping Cost: {0:C}”, overnightPackage.CalculateCost());

    }

}

The following is the expected output:

Regular Package:

  Sender's Name: Peter Anderson

  Sender's Address: 123 Main St, Ashville, NC 27111

  Recipient's Name: Mary Brown

  Recipient's Address: 456 Broad St, Benson, NC 27222

  Weight: 14

  Cost Per Ounce: $0.50

  Shipping Cost: $7.00

Two-Day Package:

  Sender's Name: Peter Anderson

  Sender's Address: 123 Main St, Ashville, NC 27111

  Recipient's Name: Mary Brown

  Recipient's Address: 456 Broad St, Benson, NC 27222

  Weight: 14

  Cost Per Ounce: $0.50

  Flat Fee: $4.00

  Shipping Cost: $11.00

Overnight Package:

  Sender's Name: Peter Anderson

  Sender's Address: 123 Main St, Ashville, NC 27111

  Recipient's Name: Mary Brown

  Recipient's Address: 456 Broad St, Benson, NC 27222

  Weight: 14

  Cost Per Ounce: $0.50

  Additional Cost Per Ounce: $0.80

  Shipping Cost: $18.20

Press any key to continue . . .

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now