Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C# Console App: An online package-delivery service, offers a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to

Using C# Console App:

An online package-delivery service, offers 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, and then include classes TwoDayPackage and OvernightPackage that derive from Package. Also create another class CostRange to calculate the cost of the package.

Base class Package should include the name, address, city for the packages sender and recipient, and instance variable that store the weight (in grams). Packages constructor should initialize the private instance variables with public properties. Ensure that the weight contains a positive value.

The class CostRange looks up the cost per gram according to the following table:

Weight (in gram)

range

Cost (per gram)

5 implies 0-5

20 cents

10 implies over 6-10

30 cents

15 implies over 11-15

35 cents

over 16

40 cents

This class should include private instance variables to specify these ranges. The class CostRange should provide a public method GetCost(decimal weight) to return a decimal value indicating the cost per ounce according to the weight range as given in the above table. For example, this method should return 30 (cents per gram) for 12 grams weight.

The class Package should provide a public method CalculateCost that creates an object of CostRange class to invoke the GetCost method which returns a decimal indicating the cost per gram. Then the method CalculateCost should determine the total cost associated with shipping the package by multiplying the weight by the cost per ounce. For example, the method should return 360 (cents cost) for 7 grams weight.

Derived class TwoDayPackage should inherit the functionality of base class Package, but also include an instance variable that represents a flat fee the shipping company charges for two-day delivery service. TwoDayPackages constructor should receive a value to initialize this instance variable. TwoDayPackage should redefinemethod CalculateCost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Packages CalculateCost method.

Class OvernightPackage should inherit directly from class Package and contain an instance variable representing an additional fee per ounce charged for overnight delivery 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

Students also viewed these Databases questions