Following this code- CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables using System; namespace RahmanA3P2InheritanceEmployee {...



Following this code- CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables



using System;



namespace RahmanA3P2InheritanceEmployee

{

    public class CommissionEmployee

{

   public string FirstName { get; }

   public string LastName { get; }

   public string SocialSecurityNumber { get; }

   private decimal grossSales; // gross weekly sales

   private decimal commissionRate; // commission percentage



   // five-parameter constructor

   public CommissionEmployee(string firstName, string lastName,

      string socialSecurityNumber, decimal grossSales,

      decimal commissionRate)

   {

      // implicit call to object constructor occurs here

      FirstName = firstName;

      LastName = lastName;

      SocialSecurityNumber = socialSecurityNumber;

      GrossSales = grossSales; // validates gross sales

      CommissionRate = commissionRate; // validates commission rate

   }



   // property that gets and sets commission employee's gross sales

   public decimal GrossSales

   {

      get

      {

         return grossSales;

      }

      set

      {

         if (value < 0) >

         {

            throw new ArgumentOutOfRangeException(nameof(value),

               value, $"{nameof(GrossSales)} must be >= 0");

         }



         grossSales = value;

      }

   }



   // property that gets and sets commission employee's commission rate

   public decimal CommissionRate

   {

      get

      {

         return commissionRate;

      }

      set

      {

         if (value <= 0 || value >= 1) // validation

         {

            throw new ArgumentOutOfRangeException(nameof(value),

               value, $"{nameof(CommissionRate)} must be > 0 and <>

         }



         commissionRate = value;

      }

   }



   // calculate commission employee's pay

   public virtual decimal Earnings() => CommissionRate * GrossSales;



   // return string representation of CommissionEmployee object

   public override string ToString() =>

      $"commission employee: {FirstName} {LastName}\n" +

      $"social security number: {SocialSecurityNumber}\n" +

      $"gross sales: {GrossSales:C}\n" +

      $"commission rate: {CommissionRate:F2}";

}

public class BasePlusCommissionEmployee : CommissionEmployee

{

   private decimal baseSalary; // base salary per week



   // six-parameter derived-class constructor

   // with call to base class CommissionEmployee constructor

   public BasePlusCommissionEmployee(string firstName, string lastName,

      string socialSecurityNumber, decimal grossSales,

      decimal commissionRate, decimal baseSalary)

      : base(firstName, lastName, socialSecurityNumber,

           grossSales, commissionRate)

   {

      BaseSalary = baseSalary; // validates base salary

   }



   // property that gets and sets

   // BasePlusCommissionEmployee's base salary

   public decimal BaseSalary

   {

      get

      {

         return baseSalary;

      }

      set

      {

         if (value < 0) >

         {

            throw new ArgumentOutOfRangeException(nameof(value),

               value, $"{nameof(BaseSalary)} must be >= 0");

         }



         baseSalary = value;

      }

   }



   // calculate earnings

   public override decimal Earnings() => BaseSalary + base.Earnings();



   // return string representation of BasePlusCommissionEmployee

   public override string ToString() =>

      $"base-salaried {base.ToString()}\nbase salary: {BaseSalary:C}";

}

public class BasePlusCommissionEmployeeTest

{

   static void Main()

   {


      // instantiate BasePlusCommissionEmployee object

      var employee = new BasePlusCommissionEmployee("Tabu", "Sham",

         "333-33-3333", 5000.00M, .04M, 300.00M);



      // display BasePlusCommissionEmployee's data

      Console.WriteLine(

         "Employee information obtained by properties and methods: \n");

      Console.WriteLine($"First name is {employee.FirstName}");

      Console.WriteLine($"Last name is {employee.LastName}");

      Console.WriteLine(

         $"Social security number is {employee.SocialSecurityNumber}");

      Console.WriteLine($"Gross sales are {employee.GrossSales:C}");

      Console.WriteLine(

         $"Commission rate is {employee.CommissionRate:F2}");

      Console.WriteLine($"Earnings are {employee.Earnings():C}");

      Console.WriteLine($"Base salary is {employee.BaseSalary:C}");



      employee.BaseSalary = 1000.00M; // set base salary



      Console.WriteLine(

         "\nUpdated employee information obtained by ToString:\n");

      Console.WriteLine(employee);

      Console.WriteLine($"earnings: {employee.Earnings():C}");

   }

}



}

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here