Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Test Program and twoDayPackage Class (Package Inheritance Hierarchy) Packag

ID: 3633974 • Letter: N

Question

Need Test Program and twoDayPackage Class

(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, stateand 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 deliver)- 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 weightbased
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 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 Packageand tests method CalculateCost.

Screen shot of packages that you will need

Package class – here is the base class which you will inherit from for the other classes such as twoDayPackage, OvernightPackage, etc..

' Class Package definition.

Public Class Package

   Private senderNameValue As String ' sender name

   Private senderAddressValue As String ' sender address

   Private senderCityValue As String ' sender city

   Private senderStateValue As String ' sender state

   Private senderZIPValue As Integer ' sender zip code

   Private recipientNameValue As String ' receiver name

   Private recipientAddressValue As String ' receiver address

   Private recipientCityValue As String ' receiver city

   Private recipientStateValue As String ' receiver state

   Private recipientZIPValue As Integer ' receiver zip

   Private weightValue As Double ' weight of the package

   Private costPerOunceValue As Decimal ' cost per ounce of the package

   ' twelve-argument constructor

   Public Sub New(ByVal sName As String, ByVal sAddress As String, _

      ByVal sCity As String, ByVal sState As String, _

      ByVal sZIP As Integer, ByVal rName As String, _

      ByVal rAddress As String, ByVal rCity As String, _

      ByVal rState As String, ByVal rZIP As Integer, _

      ByVal packageWeight As Double, ByVal cost As Decimal)

      SenderName = sName

      SenderAddress = sAddress

      SenderCity = sCity

      SenderState = sState

      SenderZIP = sZIP

      RecipientName = rName

      RecipientAddress = rAddress

      RecipientCity = rCity

      RecipientState = rState

      RecipientZIP = rZIP

      Weight = packageWeight ' validate and store weight

      CostPerOunce = cost ' validate and store cost per ounce

   End Sub ' New

   ' property SenderName

   Public Property SenderName() As String

      Get

         Return senderNameValue

      End Get

      Set(ByVal sName As String)

         senderNameValue = sName

      End Set

   End Property ' SenderName

   ' property SenderAddress

   Public Property SenderAddress() As String

      Get

         Return senderAddressValue

      End Get

      Set(ByVal sAddress As String)

         senderAddressValue = sAddress

      End Set

   End Property ' SenderAddress

   ' property SenderCity

   Public Property SenderCity() As String

      Get

         Return senderCityValue

      End Get

      Set(ByVal sCity As String)

         senderCityValue = sCity

      End Set

   End Property ' SenderCity

   ' property SenderState

   Public Property SenderState() As String

      Get

         Return senderStateValue

      End Get

      Set(ByVal sState As String)

         senderStateValue = sState

      End Set

   End Property ' SenderState

   ' property SenderZIP

   Public Property SenderZIP() As Integer

      Get

         Return senderZIPValue

      End Get

      Set(ByVal sZIP As Integer)

         senderZIPValue = sZIP

      End Set

   End Property ' SenderZIP

   ' property RecipientName

   Public Property RecipientName() As String

      Get

         Return recipientNameValue

      End Get

      Set(ByVal rName As String)

         recipientNameValue = rName

      End Set

   End Property ' RecipientName

   ' property RecipientAddress

   Public Property RecipientAddress() As String

      Get

         Return recipientAddressValue

      End Get

      Set(ByVal rAddress As String)

         recipientAddressValue = rAddress

      End Set

   End Property ' RecipientAddress

   ' property RecipientCity

   Public Property RecipientCity() As String

      Get

         Return recipientCityValue

      End Get

      Set(ByVal rCity As String)

         recipientCityValue = rCity

      End Set

   End Property ' RecipientCity

   ' property RecipientState

   Public Property RecipientState() As String

      Get

         Return recipientStateValue

      End Get

      Set(ByVal rState As String)

         recipientStateValue = rState

      End Set

   End Property ' RecipientState

   ' property RecipientZIP

   Public Property RecipientZIP() As Integer

      Get

         Return recipientZIPValue

      End Get

      Set(ByVal rZIP As Integer)

         recipientZIPValue = rZIP

      End Set

   End Property ' RecipientZIP

   ' property Weight

   Public Property Weight() As Double

      Get

         Return weightValue

      End Get

      Set(ByVal packageWeight As Double)

         If packageWeight < 0.0 Then ' validate package weight

            weightValue = 0.0

         Else

            weightValue = packageWeight

         End If

      End Set

   End Property ' Weight

   ' property CostPerOunce

   Public Property CostPerOunce() As Decimal

      Get

         Return costPerOunceValue

      End Get

      Set(ByVal cost As Decimal)

         If cost < 0D Then ' validate cost per ounce

            costPerOunceValue = 0D

         Else

            costPerOunceValue = cost

         End If

      End Set

   End Property ' CostPerOunce

   ' calculate shipping cost for package

   Public Overridable Function CalculateCost() As Decimal

      Return Convert.ToDecimal(Weight) * CostPerOunce

   End Function ' CalculateCost

   ' display package information

   Public Overrides Function ToString() As String

      Return ("Regular Service" & vbNewLine & "Sender:" & vbNewLine & _

         SenderName & vbNewLine & SenderAddress & vbNewLine & _

         SenderCity & ", " & SenderState & " " & SenderZIP & _

         vbNewLine & vbNewLine & "Recipient:" & vbNewLine & _

         RecipientName & vbNewLine & RecipientAddress & vbNewLine & _

         RecipientCity & ", " & RecipientState & " " & RecipientZIP)

   End Function ' ToString

End Class ' Package

OvernightPackage

Here is the code for the OvernightPackage – it shows you how you would use the package class.

' Exercise 11.9 Solution: OvernightPackage.vb

' Class OvernightPackage definition.

Public Class OvernightPackage

   Inherits Package

   ' fee per ounce for overnight delivery

   Private overnightFeePerOunceValue As Decimal

   ' thirteen-argument constructor

   Public Sub New(ByVal sName As String, ByVal sAddress As String, _

      ByVal sCity As String, ByVal sState As String, _

      ByVal sZIP As Integer, ByVal rName As String, _

      ByVal rAddress As String, ByVal rCity As String, _

      ByVal rState As String, ByVal rZIP As Integer, _

      ByVal packageWeight As Double, ByVal cost As Decimal, _

      ByVal fee As Decimal)

      MyBase.New(sName, sAddress, sCity, sState, sZIP, rName, rAddress, _

         rCity, rState, rZIP, packageWeight, cost)

      OvernightFeePerOunce = fee ' validate overnight fee per ounce

   End Sub ' New

   ' property OvernightFeePerOunce

   Public Property OvernightFeePerOunce() As Decimal

      Get

         Return overnightFeePerOunceValue

      End Get

      Set(ByVal fee As Decimal)

         If fee < 0D Then ' validate overnight fee per ounce

            overnightFeePerOunceValue = 0D

         Else

            overnightFeePerOunceValue = fee

         End If

      End Set

   End Property ' OvernightFeePerOunce

   ' calculate shipping cost for package

   Public Overrides Function CalculateCost() As Decimal

      Return MyBase.CalculateCost() + _

         Convert.ToDecimal(Weight) * OvernightFeePerOunce

   End Function ' CalculateCost

   ' display package information

   Public Overrides Function ToString() As String

      Return ("Overnight Service" & vbNewLine & "Sender:" & vbNewLine & _

         SenderName & vbNewLine & SenderAddress & vbNewLine & _

         SenderCity & ", " & SenderState & " " & SenderZIP & _

         vbNewLine & vbNewLine & "Recipient:" & vbNewLine & _

         RecipientName & vbNewLine & RecipientAddress & vbNewLine & _

         RecipientCity & ", " & RecipientState & " " & RecipientZIP)

   End Function ' ToString

End Class ' OvernightPackage

Screen shot of packages that you will need


Package class – here is the base class which you will inherit from for the other classes such as twoDayPackage, OvernightPackage, etc..

' Class Package definition.

Public Class Package

   Private senderNameValue As String ' sender name

   Private senderAddressValue As String ' sender address

   Private senderCityValue As String ' sender city

   Private senderStateValue As String ' sender state

   Private senderZIPValue As Integer ' sender zip code

   Private recipientNameValue As String ' receiver name

   Private recipientAddressValue As String ' receiver address

   Private recipientCityValue As String ' receiver city

   Private recipientStateValue As String ' receiver state

   Private recipientZIPValue As Integer ' receiver zip

   Private weightValue As Double ' weight of the package

   Private costPerOunceValue As Decimal ' cost per ounce of the package

   ' twelve-argument constructor

   Public Sub New(ByVal sName As String, ByVal sAddress As String, _

      ByVal sCity As String, ByVal sState As String, _

      ByVal sZIP As Integer, ByVal rName As String, _

      ByVal rAddress As String, ByVal rCity As String, _

      ByVal rState As String, ByVal rZIP As Integer, _

      ByVal packageWeight As Double, ByVal cost As Decimal)

      SenderName = sName

      SenderAddress = sAddress

      SenderCity = sCity

      SenderState = sState

      SenderZIP = sZIP

      RecipientName = rName

      RecipientAddress = rAddress

      RecipientCity = rCity

      RecipientState = rState

      RecipientZIP = rZIP

      Weight = packageWeight ' validate and store weight

      CostPerOunce = cost ' validate and store cost per ounce

   End Sub ' New

   ' property SenderName

   Public Property SenderName() As String

      Get

         Return senderNameValue

      End Get

      Set(ByVal sName As String)

         senderNameValue = sName

      End Set

   End Property ' SenderName

   ' property SenderAddress

   Public Property SenderAddress() As String

      Get

         Return senderAddressValue

      End Get

      Set(ByVal sAddress As String)

         senderAddressValue = sAddress

      End Set

   End Property ' SenderAddress

   ' property SenderCity

   Public Property SenderCity() As String

      Get

         Return senderCityValue

      End Get

      Set(ByVal sCity As String)

         senderCityValue = sCity

      End Set

   End Property ' SenderCity

   ' property SenderState

   Public Property SenderState() As String

      Get

         Return senderStateValue

      End Get

      Set(ByVal sState As String)

         senderStateValue = sState

      End Set

   End Property ' SenderState

   ' property SenderZIP

   Public Property SenderZIP() As Integer

      Get

         Return senderZIPValue

      End Get

      Set(ByVal sZIP As Integer)

         senderZIPValue = sZIP

      End Set

   End Property ' SenderZIP

   ' property RecipientName

   Public Property RecipientName() As String

      Get

         Return recipientNameValue

      End Get

      Set(ByVal rName As String)

         recipientNameValue = rName

      End Set

   End Property ' RecipientName

   ' property RecipientAddress

   Public Property RecipientAddress() As String

      Get

         Return recipientAddressValue

      End Get

      Set(ByVal rAddress As String)

         recipientAddressValue = rAddress

      End Set

   End Property ' RecipientAddress

   ' property RecipientCity

   Public Property RecipientCity() As String

      Get

         Return recipientCityValue

      End Get

      Set(ByVal rCity As String)

         recipientCityValue = rCity

      End Set

   End Property ' RecipientCity

   ' property RecipientState

   Public Property RecipientState() As String

      Get

         Return recipientStateValue

      End Get

      Set(ByVal rState As String)

         recipientStateValue = rState

      End Set

   End Property ' RecipientState

   ' property RecipientZIP

   Public Property RecipientZIP() As Integer

      Get

         Return recipientZIPValue

      End Get

      Set(ByVal rZIP As Integer)

         recipientZIPValue = rZIP

      End Set

   End Property ' RecipientZIP

   ' property Weight

   Public Property Weight() As Double

      Get

         Return weightValue

      End Get

      Set(ByVal packageWeight As Double)

         If packageWeight < 0.0 Then ' validate package weight

            weightValue = 0.0

         Else

            weightValue = packageWeight

         End If

      End Set

   End Property ' Weight

   ' property CostPerOunce

   Public Property CostPerOunce() As Decimal

      Get

         Return costPerOunceValue

      End Get

      Set(ByVal cost As Decimal)

         If cost < 0D Then ' validate cost per ounce

            costPerOunceValue = 0D

         Else

            costPerOunceValue = cost

         End If

      End Set

   End Property ' CostPerOunce

   ' calculate shipping cost for package

   Public Overridable Function CalculateCost() As Decimal

      Return Convert.ToDecimal(Weight) * CostPerOunce

   End Function ' CalculateCost

   ' display package information

   Public Overrides Function ToString() As String

      Return ("Regular Service" & vbNewLine & "Sender:" & vbNewLine & _

         SenderName & vbNewLine & SenderAddress & vbNewLine & _

         SenderCity & ", " & SenderState & " " & SenderZIP & _

         vbNewLine & vbNewLine & "Recipient:" & vbNewLine & _

         RecipientName & vbNewLine & RecipientAddress & vbNewLine & _

         RecipientCity & ", " & RecipientState & " " & RecipientZIP)

   End Function ' ToString

End Class ' Package

OvernightPackage

Here is the code for the OvernightPackage – it shows you how you would use the package class.

' Exercise 11.9 Solution: OvernightPackage.vb

' Class OvernightPackage definition.

Public Class OvernightPackage

   Inherits Package

   ' fee per ounce for overnight delivery

   Private overnightFeePerOunceValue As Decimal

   ' thirteen-argument constructor

   Public Sub New(ByVal sName As String, ByVal sAddress As String, _

      ByVal sCity As String, ByVal sState As String, _

      ByVal sZIP As Integer, ByVal rName As String, _

      ByVal rAddress As String, ByVal rCity As String, _

      ByVal rState As String, ByVal rZIP As Integer, _

      ByVal packageWeight As Double, ByVal cost As Decimal, _

      ByVal fee As Decimal)

      MyBase.New(sName, sAddress, sCity, sState, sZIP, rName, rAddress, _

         rCity, rState, rZIP, packageWeight, cost)

      OvernightFeePerOunce = fee ' validate overnight fee per ounce

   End Sub ' New

   ' property OvernightFeePerOunce

   Public Property OvernightFeePerOunce() As Decimal

      Get

         Return overnightFeePerOunceValue

      End Get

      Set(ByVal fee As Decimal)

         If fee < 0D Then ' validate overnight fee per ounce

            overnightFeePerOunceValue = 0D

         Else

            overnightFeePerOunceValue = fee

         End If

      End Set

   End Property ' OvernightFeePerOunce

   ' calculate shipping cost for package

   Public Overrides Function CalculateCost() As Decimal

      Return MyBase.CalculateCost() + _

         Convert.ToDecimal(Weight) * OvernightFeePerOunce

   End Function ' CalculateCost

   ' display package information

   Public Overrides Function ToString() As String

      Return ("Overnight Service" & vbNewLine & "Sender:" & vbNewLine & _

         SenderName & vbNewLine & SenderAddress & vbNewLine & _

         SenderCity & ", " & SenderState & " " & SenderZIP & _

         vbNewLine & vbNewLine & "Recipient:" & vbNewLine & _

         RecipientName & vbNewLine & RecipientAddress & vbNewLine & _

         RecipientCity & ", " & RecipientState & " " & RecipientZIP)

   End Function ' ToString

End Class ' OvernightPackage

Explanation / Answer

#include #include #include using namespace std; // This class Package is the base class for two other classes, TwoDayPackage and OverNightPackage.// class Package // begins class Package { public: Package(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0); // constructor // set and get functions for sender void setSendName(const string &); string getSendName() const; void setSendAdd(const string &); string getSendAdd() const; void setSendCity(const string &); string getSendCity() const; void setSendSt(const string &); string getSendSt() const; void setSendZip(const string &); string getSendZip() const; // set and get functions for recipient void setRecName(const string &); string getRecName() const; void setRecAdd(const string &); string getRecAdd() const; void setRecipientCity(const string &); string getRecipientCity() const; void setRecSt(const string &); string getRecSt() const; void setRecZip(const string &); string getRecZip() const; void setWt(double); double getWt() const; void setShip(double); double getShip() const; double CalCost() const; private: string sendName; string sendAdd; string sendCity; string sendState; string sendZip; string recName; string recAdd; string recCity; string recState; string recZip; double wt; double shipCost; }; Package::Package(const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szipcode, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzipcode, double wt, double shipCost) { sendName = sname; sendAdd = saddress; sendCity = scity; sendState = sstate; sendZip = szipcode; recName = rname; recAdd = raddress; recCity = rcity; recState = rstate; recZip = rzipcode; setWt(wt); setShip(shipCost); } void Package::setSendName(const string &sname) { sendName = sname; } string Package::getSendName() const { return sendName; } void Package::setSendAdd(const string &saddress) { sendAdd = saddress; } string Package::getSendAdd() const { return sendAdd; } void Package::setSendCity(const string &scity) { sendCity = scity; } string Package::getSendCity() const { return sendCity; } void Package::setSendSt(const string &sstate) { sendState = sstate; } string Package::getSendSt() const { return sendState; } void Package::setSendZip(const string &szipcode) { sendZip = szipcode; } string Package::getSendZip() const { return sendZip; } void Package::setRecName(const string &rname) { recName = rname; } string Package::getRecName() const { return recName; } void Package::setRecAdd(const string &raddress) { recAdd = raddress; } string Package::getRecAdd() const { return recAdd; } void Package::setRecipientCity(const string &rcity) { recCity = rcity; } string Package::getRecipientCity() const { return recCity; } void Package::setRecSt(const string &rstate) { recState = rstate; } string Package::getRecSt() const { return recState; } void Package::setRecZip(const string &rzipcode) { recZip = rzipcode; } string Package::getRecZip() const { return recZip; } void Package::setWt(double wt) { wt = (wt < 0.0 ) ? 0.0 : wt; } double Package::getWt() const { return wt; } void Package::setShip(double shipCost) { shipCost = ( shipCost < 0.0) ? 0.0 : shipCost; } double Package::getShip() const { return shipCost; } double Package::CalCost() const { return wt * shipCost; } // This class TwoDayPackage is the first derived class from class Package.// class TDP : public Package { public: TDP(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); // constructor void setFlatFee(double); double getFlatFee() const; void CalCost() const; private: double flatFee; }; // This class OverNightPackage is the second derived class from class Package.// class ONP : public Package { public: ONP(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double=0.0, double=0.0, double=0.0); // constructor void setFee(double); double getFee() const; void CalCost() const; private: double fee; }; // This is the test program.// int main() { ONP box("name", "123 this Street", "boston", "ma", "12345", "receiver", "123 that street", "medford", "ma", "25341", 10.00, 1.50, .85); TDP parcel("name2", "123 1st Street", "orlando", "fl", "56474", "receiver2", "833 2nd Street", "miami", "fl", "88472", 15.00, 1.05, 5.00); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote