Question
Create a C# console application named PackageDemo that declares and demonstrates objects of the package class and its descendants. The package class includes auto-implemented properties
Create a C# console application named PackageDemo that declares and demonstrates objects of the package class and its descendants. The package class includes auto-implemented properties for an id number, recipients name, and weight in ounces. The class also comntins a delivery price feild that is set when the weight is set as $5 for the first 32 ounces and 12 cents per ounce for every ounce over 32. b. Create a child class named InsuredPackage, which includes a field for the package's value. Override the method that sets a Package's delivery price to include insurance, which is $1 for packages valued up to $20 and $2.50 for packages valued $20 or more.
Heres my Code. My DeliveryPrice returns a zero value and my Insrurance gives me an error. How do I fix this?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console;
namespace PackageDemo { class demo { static void Main() { Package LightP = new Package( ); Package HeavyP = new Package(); LightP.ID = "4455"; LightP.Name = "Carpenter"; LightP.Weight = 32;
WriteLine("Name -> " + LightP.Name); WriteLine("Package ID -> " + LightP.ID); WriteLine("Ounces -> " + LightP.Weight); WriteLine("Charges -> " + LightP.DeliveryPrice);
HeavyP.ID = "8755"; HeavyP.Name = "Lee"; HeavyP.Weight = 33;
WriteLine("Name -> " + HeavyP.Name); WriteLine("Package ID -> " + HeavyP.ID); WriteLine("Ounces -> " + HeavyP.Weight); WriteLine("Charges -> " + HeavyP.DeliveryPrice);
Package InexpensiveP = new Package(); Package ExpensiveP = new Package();
InexpensiveP.ID = "5901"; InexpensiveP.Name = "Conner"; InexpensiveP.Weight = 10; InexpensiveP.PkgValue = 19.99;
WriteLine("Name -> " + InexpensiveP.Name); WriteLine("Package ID -> " + InexpensiveP.ID); WriteLine("Ounces -> " + InexpensiveP.Weight); WriteLine("Charges -> " + InexpensiveP.DeliveryPrice); WriteLine("Insrurance -> " + InexpensiveP.Insrurance);
ExpensiveP.ID = "5902"; ExpensiveP.Name = "Unger"; ExpensiveP.Weight = 10; ExpensiveP.PkgValue = 20;
WriteLine("Name -> " + ExpensiveP.Name); WriteLine("Package ID -> " + ExpensiveP.ID); WriteLine("Ounces -> " + ExpensiveP.Weight); WriteLine("Charges -> " + ExpensiveP.DeliveryPrice); WriteLine("Insrurance -> " + ExpensiveP.Insrurance);
ReadLine(); }
} class Package { private double deliveryPrice; private string iD; private string name; private int weight; private double pkgValue;
public double DeliveryPrice { get { return deliveryPrice; } set { if (weight <= 32) { deliveryPrice = 5.00; } else { double MoreThan = weight - 32; deliveryPrice = (MoreThan * .12) + 5.00; } } }
public string ID { get { return iD; } set { iD = value; } }
public string Name { get { return name; } set { name = value; } }
public int Weight { get { return weight; } set { weight = value; } }
public double PkgValue { get { return pkgValue; } set { pkgValue = value; } } } class InsuredPackage : Package { private double pkgValue; private double insurance;
public double Insrurance { get { return insurance; } set { pkgValue = value;
if (this.pkgValue <= 20) insurance = 1.00;
else if (this.pkgValue > 20) insurance = 2.50; } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started