Okay, I am going to try this for the 5th time can some please show me what the c
ID: 3672812 • Letter: O
Question
Okay, I am going to try this for the 5th time can some please show me what the code in C# that I am missing?
I have an issue with the line 109 public InsuredPackage (double package value)
error message I need an argument to correspond to required formal parmenter "ounce of Package.Pack (int)
I am can't figure out how to override the method that sets the package delivery price to include insurance
This is my code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PackageDemo
{
public class Package
{
public static void main()
{ }
//Parent class
/*Parent class package that has methods to set ounces
and calculates the delivery charges */
public int packageID;
public int ounces;
public double deliveryCharges;
public string name;
//Constructor that sets the number of ounces
public Package(int ounces)
{
//generage package id a random number
Random idnumber = new Random();
packageID = idnumber.Next(1, 999);
}
//method to delivery charges
public double deliverycharges(double deliveryCharges)
{
this.deliveryCharges = deliveryCharges;
return deliveryCharges;
}
public string getName()
{
System.Console.WriteLine("Enter name");
return name;
}
public int getID()
{
return packageID;
}
//Private method that set ounces and call
//setDeliveryCharges
private void setOunces(int ounces)
{
this.ounces = ounces;
setDeliveryCharges(ounces);
}
//Set delivery charges of package of weight ounces
private void setDeliveryCharges(int ounces)
{
if (ounces <= 32)
//set charge
deliveryCharges = 5;
else
{
//set ounces grater than 32
int remainingOunces = (ounces - 5);
deliveryCharges = 5 + remainingOunces * 0.12;
}
}
//return ounces
public int getOunces()
{
return ounces;
}
//Return delivery charges
public double getDeliveryCharges()
{
return deliveryCharges;
}
}
//Child class
/**The class InsuredPackage that extends the Package
* class that pass the deliveryCharges to the
* base class package and get the deliverycharge
* fee from base class in getInsuranceFee class*/
public class InsuredPackage : Package
{
private double packagevalue;
//constructor to set delivery charges for insured package
public InsuredPackage( double packagevalue )
{
this.packagevalue = packagevalue;
}
/**Returns the insurance fee based on the delivery charges
* fee*/
public double getInsuranceFee()
{
if (packagevalue < 20)
return 1;
else
return 2.50;
}
}
class PackageDemo
{
static void main()
{
//Create an instance of Package with ounces as input
Package package1 = new Package(25);
System.Console.WriteLine("name" + package1.getName());
System.Console.WriteLine("Package ID : " + package1.getID());
System.Console.WriteLine("ounces : " + package1.getOunces());
System.Console.WriteLine("Charges : " + package1.getDeliveryCharges());
//Create an instance of InsuredPackage with package value
InsuredPackage insuredPackage = new InsuredPackage(50);
//here using all the pmethos of parent calss without creating again in child class
//CALLING parent method setName() using child class object
System.Console.WriteLine("name" + insuredPackage.getName());
//calling parent methods using child class object
System.Console.WriteLine("Package ID : " + insuredPackage.getID());
System.Console.WriteLine("ounces : " + insuredPackage.getOunces());
System.Console.WriteLine("Charges : " + insuredPackage.getDeliveryCharges());
//CALLING same class method
System.Console.WriteLine("Insureance fee : "
+ insuredPackage.getInsuranceFee());
}
}
}
Explanation / Answer
Below code is working fine without error. Please check.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PackageDemo
{
public class Package
{
public static void main()
{ }
//Parent class
/*Parent class package that has methods to set ounces
and calculates the delivery charges */
public int packageID;
public int ounces;
public double deliveryCharges;
public string name;
//Constructor that sets the number of ounces
public Package(int ounces)
{
//generage package id a random number
Random idnumber = new Random();
packageID = idnumber.Next(1, 999);
}
//method to delivery charges
public double deliverycharges(double deliveryCharges)
{
this.deliveryCharges = deliveryCharges;
return deliveryCharges;
}
public string getName()
{
System.Console.WriteLine("Enter name");
return name;
}
public int getID()
{
return packageID;
}
//Private method that set ounces and call
//setDeliveryCharges
private void setOunces(int ounces)
{
this.ounces = ounces;
setDeliveryCharges(ounces);
}
//Set delivery charges of package of weight ounces
private void setDeliveryCharges(int ounces)
{
if (ounces <= 32)
//set charge
deliveryCharges = 5;
else
{
//set ounces grater than 32
int remainingOunces = (ounces - 5);
deliveryCharges = 5 + remainingOunces * 0.12;
}
}
//return ounces
public int getOunces()
{
return ounces;
}
//Return delivery charges
public double getDeliveryCharges()
{
return deliveryCharges;
}
}
//Child class
/**The class InsuredPackage that extends the Package
* class that pass the deliveryCharges to the
* base class package and get the deliverycharge
* fee from base class in getInsuranceFee class*/
public class InsuredPackage : Package
{
private double packagevalue;
//constructor to set delivery charges for insured package
public InsuredPackage( double packagevalue )
{
this.packagevalue = packagevalue;
}
/**Returns the insurance fee based on the delivery charges
* fee*/
public double getInsuranceFee()
{
if (packagevalue < 20)
return 1;
else
return 2.50;
}
}
class PackageDemo
{
static void main()
{
//Create an instance of Package with ounces as input
Package package1 = new Package(25);
System.Console.WriteLine("name" + package1.getName());
System.Console.WriteLine("Package ID : " + package1.getID());
System.Console.WriteLine("ounces : " + package1.getOunces());
System.Console.WriteLine("Charges : " + package1.getDeliveryCharges());
//Create an instance of InsuredPackage with package value
InsuredPackage insuredPackage = new InsuredPackage(50);
//here using all the pmethos of parent calss without creating again in child class
//CALLING parent method setName() using child class object
System.Console.WriteLine("name" + insuredPackage.getName());
//calling parent methods using child class object
System.Console.WriteLine("Package ID : " + insuredPackage.getID());
System.Console.WriteLine("ounces : " + insuredPackage.getOunces());
System.Console.WriteLine("Charges : " + insuredPackage.getDeliveryCharges());
//CALLING same class method
System.Console.WriteLine("Insureance fee : "
+ insuredPackage.getInsuranceFee());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.