answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makvit [3.9K]
1 year ago
10

(Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o

ptions, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes Two Day Package and Over night Package that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP code for both the sender and the recipient of the package, in addition to data members that store the weight (in ounces) and cost per ounce to ship the package. Package’s constructor should initialize these data members. Ensure that the weight and cost per ounce contain positive values. Package should provide a public member function calculate Cost that returns a double indicating the cost associated with shipping the package. Package’s calculate Cost function should determine the cost by multiplying the weight by the cost per ounce. Derived class Two Day Package should inherit the functionality of base class Package, but also include a data member that represents a flat fee that the shipping company charges for two-day-delivery service. Two Day Package’s constructor should receive a value to initialize this data member. Two Day Package should redefine member function calculate Cost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Package’s calculate Cost function. Class Over night Package should inherit directly from class Package and contain an additional data member representing an additional fee per ounce charged for overnight-delivery service. Over night Package should redefine member function calculate Cost so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost. Write a test program that creates objects of each type of Package and tests member function calculate Cost.

Computers and Technology
1 answer:
lys-0071 [83]1 year ago
8 0

Answer:

Check the explanation

Explanation:

note: code is implemented as per the main method provided:

code:

using System;

public class Package

{

string senderName11;

string senderAddress1;

string senderCity1;

string senderState1;

string senderZip1;

string recipientName1;

string recipientAddress1;

string recipientCity1;

string recipientState1;

string recipientZip1;

decimal weight1;

decimal costPerOunce1;

public string SenderName11

{

get { return senderName11; }

set { senderName11 = value; }

}

public string SenderAddress1

{

get { return senderAddress1; }

set { senderAddress1 = value; }

}

public string SenderCity1

{

get { return senderCity1; }

set { senderCity1 = value; }

}

public string SenderState1

{

get { return senderState1; }

set { senderState1 = value; }

}

public string SenderZip1

{

get { return senderZip1;}

set { senderZip1 = value; }

}

public string RecipientName1

{

get { return recipientName1; }

set { recipientName1 = value; }

}

public string RecipientAddress1

{

get { return recipientAddress1; }

set { recipientAddress1 = value; }

}

public string RecipientCity1

{

get { return recipientCity1; }

set { recipientCity1 = value; }

}

public string RecipientState1

{

get { return recipientState1; }

set { recipientState1 = value; }

}

public string RecipientZip1

{

get { return recipientZip1; }

  set { recipientZip1 = value; }

}

public decimal Weight1

{

get { return weight1; }

set

{

if (value > 0)

weight1 = value;

else

Console.WriteLine("Weight1 can't be less tha zero");

}

}

public decimal CostPerOunce1

{

get { return costPerOunce1; }

set

{

if (value > 0)

costPerOunce1 = value;

else

Console.WriteLine("Cost per ounce can't be less than zero");

)

{

SenderName11 = senderName11;

SenderAddress1 = senderAddress1;

)

{

TwoDayDeliveryFee = twoDayDeliveryFee;

}

public override decimal CalculateCost()

{

return base.CalculateCost() + TwoDayDeliveryFee;

}

OvernightDeliveryFeePerOunce = overnightDeliveryFeePerOunce;

}

public override decimal CalculateCost()

{

return (CostPerOunce1 + OvernightDeliveryFeePerOunce) * Weight1;

}

}

class TestPackages

{

static void Main(string[] args)

{

Package regularPackage = new Package

(

"Peter Anderson",

"123 Main St, Ashville, NC 27111 ",

"Ashville",

"NC 27111",

"MN 55416",

"Mary Brown",

"456 Broad St Benson, NC 27222",

"St. Petersburg",

"Benson",

"NC 27222",

160M,

0.1M

);

Console.WriteLine("\nRegular Package: ");

  Console.WriteLine(" Sender's Name: {0}",

      regularPackage.SenderName11);

  Console.WriteLine(" Sender's Address: {0}",

      regularPackage.SenderAddress1);

  Console.WriteLine(" Recipient's Name: {0}",

       regularPackage.RecipientName1);

  Console.WriteLine(" Recipient's Address: {0}",

       regularPackage.RecipientAddress1);

  Console.WriteLine(" Weight1: {0}"

, regularPackage.Weight1);

  Console.WriteLine(" Cost Per Ounce: {0:C}",

       regularPackage.CostPerOunce1);

  Console.WriteLine("Shipping Cost: {0:C}",

       regularPackage.CalculateCost());

Console.WriteLine(regularPackage.CalculateCost());

 

TwoDayPackage twoDayPackage = new TwoDayPackage

(

"Peter Anderson",

"123 Main St 123 Main St, Ashville, NC 27111",

"Ashville",

"NC 27111",

"MN 55416",

"Mary Brown",

"456 Broad St",

"St. Petersburg",

"Benson",

"NC 27222",

160M,

0.1M,

1.5M

);

  Console.WriteLine("\nTwo-Day Package: ");

  Console.WriteLine(" Sender's Name: {0}",

  twoDayPackage.SenderName11);

Console.WriteLine(" Sender's Address: {0}",

twoDayPackage.SenderAddress1);

  Console.WriteLine(" Recipient's Name: {0}",

   twoDayPackage.RecipientName1);

  Console.WriteLine(" Recipient's Address: {0}",

   twoDayPackage.RecipientAddress1);

  Console.WriteLine(" Weight1: {0}", twoDayPackage.Weight1);

  Console.WriteLine(" Cost Per Ounce: {0:C}",

   twoDayPackage.CostPerOunce1);

  Console.WriteLine(" Flat Fee: {0:C}",

   twoDayPackage.Weight1);

  Console.WriteLine(" Shipping Cost: {0:C}",

   twoDayPackage.CalculateCost());

OvernightPackage overnightPackage = new OvernightPackage

(

"Peter Anderson",

"123 Main St 123 Main St, Ashville, NC 27111",

"Ashville",

"NC 27111",

"MN 55416",

"Mary Brown",

"456 Broad St Benson, NC 27222",

"St. Petersburg",

"Benson",

"NC 27222",

160M,

0.1M,

1.5M

);

Console.WriteLine("\nOvernight Package: ");

  Console.WriteLine(" Sender's Name: {0}",

   overnightPackage.SenderName11);

  Console.WriteLine(" Sender's Address: {0}",

   overnightPackage.SenderAddress1);

  Console.WriteLine(" Recipient's Name: {0}",

   overnightPackage.RecipientName1);

  Console.WriteLine(" Recipient's Address: {0}",

   overnightPackage.RecipientAddress1);

  Console.WriteLine(" Weight1: {0}",

   overnightPackage.Weight1);

  Console.WriteLine(" Cost Per Ounce: {0:C}",

   overnightPackage.CostPerOunce1);

  Console.WriteLine(" Additional Cost Per Ounce: {0:C}",

   overnightPackage.OvernightDeliveryFeePerOunce);

  Console.WriteLine(" Shipping Cost: {0:C}",

   overnightPackage.CalculateCost());

Console.WriteLine(overnightPackage.CalculateCost()); Console.ReadKey();

}

}

The Result can be seen below:

You might be interested in
Jason is working on a web page that includes Q&A interactions. Which option should Jason select to engage users in the inter
Vaselesa [24]
E should be the correct answer
0 0
1 year ago
Read 2 more answers
What is the argument in this function =AVERAGE(F3:F26)
monitta
The argument for the function would be answer "D".
5 0
1 year ago
3.34 LAB: Mad Lib - loops in C++
Ganezh [65]

Answer:

A Program was written to carry out some set activities. below is the code program in C++ in the explanation section

Explanation:

Solution

CODE

#include <iostream>

using namespace std;

int main() {

string name; // variables

int number;

cin >> name >> number; // taking user input

while(number != 0)

{

// printing output

cout << "Eating " << number << " " << name << " a day keeps the doctor away." << endl;

// taking user input again

cin >> name >> number;

}

}

Note: Kindly find an attached copy of the compiled program output to this question.

7 0
1 year ago
Which element of the word program window contains buttons for saving a document and for undoing, redoing, and repeating a change
miskamm [114]
The answer is the Quick Access Toolbar. However, it is not only for saving files or undoing your work. Containing a set of commands that are independent, this toolbar is actually customizable wherein you could change these icons to the ones you really need and frequently use. By tweaking the settings, you can even add commands to the Quick Access Toolbar that are not in the ribbon (like New, Open and Print).
7 0
2 years ago
Two women are on either side of a high fence. One of the women, named Apple- server, has a beautiful apple tree loaded with deli
ZanzabumX [31]

Answer:

ok cool

Explanation:

kkk

6 0
2 years ago
Other questions:
  • Computer design software requires __________________ to be used properly and successfully by architects.
    9·2 answers
  • Based on a kc value of 0.150 and the data table given, what are the equilibrium concentrations of xy, x, and y, respectively?
    9·1 answer
  • In the game Beehive, you play the role of a worker bee who must watch over her hive. Your duties include (among others) directin
    12·2 answers
  • When Jen is planning to upgrade to a monitor with a better resolution, what should she be looking for in the new monitor? machin
    11·1 answer
  • Robert needs to apply formatting from one set of text to multiple other sets of text throughout the document. Which option shoul
    7·1 answer
  • You realize your computer has been infected with malware. It seems as if someone is controlling your computer from a remote loca
    5·1 answer
  • A Color class has a method getColorName that returns a string corresponding to the common name for the color, e.g., yellow, blue
    11·1 answer
  • Determining the Services Running on a Network Alexander Rocco Corporation has multiple OSs running in its many branch offices. B
    10·1 answer
  • A machine is having issues, so the user is responsible for getting the machine serviced. Which stage of the hardware lifecycle d
    13·1 answer
  • Exercise 3.6.9: 24 vs. "24"5 points
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!