Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

(Package Inheritance Hierarchy)

Faten
Faten 


(Package Inheritance Hierarchy) 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 include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include private instance variables representing the name, address, city, state and ZIP code for the package's sender and recipient, and instance variables that store the weight (in ounces) and cost per ounce to ship the package. Package's constructor should initialize these private instance variables with public properties. Ensure that the weight and cost per ounce contain positive 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 an instance variable that represents a flat fee that the shipping company charges for two-day delivery service. TwoDayPackage's constructor should receive a value to initialize this instance variable. TwoDayPackage 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 Package's CalculateCost method. Class OvernightPackage should inherit directly from class Package and contain an instance variable representing an additional fee per ounce charged for overnightdelivery service. OvernightPackage should redefine method CalculateCost so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost. Write a test application that creates objects of each type of Package and tests method CalculateCost. Attachments
Tags
Clarifications

Answers

C# - Package Inheritance Hierarchy

dickersonka
dickersonka 



Attached is the solution to the package delivery assignment in c# including source and comments Attachments
PackageDelivery.zip (34 K) Download









Preview
C:\Development\Cash4Scholars\PackageDelivery\PackageDelivery\bin\Debug\PackageDelivery.pdb

Preview
: base(senderName, senderAddress, senderCity, senderState, senderZip, recipientName, recipientAddress, recipientCity, recipientState, recipientZip, weight, costPerOunce) { this.feePerOunce = feePerOunce; } public override double CalculateCost() { //base cost + additional fee

Preview
this.senderState = value; } } public String SenderZip { get { return this.senderZip; } set { this.senderZip = value; } } public String RecipientName { get { return this.recipientName; } set { this.recipientName = value; }

Preview
results Console.WriteLine("Two Day Package"); Console.WriteLine("Weight: " + twoDay.Weight); Console.WriteLine("Cost Per Ounce: " + twoDay.CostPerOunce); Console.WriteLine("Flat Fee: " + twoDay.FlatFee); Console.WriteLine("Cost: " + twoDay.CalculateCost()); Console.WriteLine("--------------------------"); //create overnight package OvernightPackage overnight = new OvernightPackage("John Jones", "1 Way", "New York", "NY", "12345",

Preview
AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID

Preview
recipientState, recipientZip, weight, costPerOunce) { this.flatFee = flatFee; } public override double CalculateCost() { //base cost + flat fee return base.CalculateCost() + this.flatFee; }

Screenshots
Purchase Answer