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

C#: Inheritance rite a program named SalespersonDemo that instantiates objects u

ID: 3699157 • Letter: C

Question

C#: Inheritance

rite a program named SalespersonDemo that instantiates objects using classes named RealEstateSalesperson and Gir1Scout. Demonstrate that each object can use a SalesSpeech ( method appropriately. Also, use a MakeSale() method two or three times with each object, and display the final contents of each object's data fields. First, create an abstract class named Salesperson. Fields include first and last names; the Salesperson constructor requires both these values. Include properties for the fields. Include a method that returns a string that holds the Salesperson's full name-the first and last names separated by a space. Then perform the following tasks: . Create two child classes of Salesperson: RealEstateSalesperson and GirlScout. The RealEstateSalesperson class contains fields for total value sold in dollars and total commission earned (both of which are initialized to 0), and mission rate field required by the class constructor. The GirlScout class includes a field to hold the number of boxes of cookies sold, which is initialized to 0 Include properties for every field . Create an interface named ISellable that contains two methods: Salesspeecho akeSaleO. In each RealEstateSalesperson and GirlScout class and M implemen speech that the objects of the class could use t SalesSpeech ) to display an appropriate one- or two-sentence sales alesperson class, implement the MakeSaleO method to accept an integer dollar value for a house, add the value to the RealEstateSalesperson's total value sold, and compute the total commission earned. In the GirlScout class implement the MakeSaleO method to accept an integer representing the number of boxes of cookies sold and add it to the total field

Explanation / Answer

//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalespersonDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            RealEstateSalesperson res = new RealEstateSalesperson("Bob", "Rey", 0.99f);
            GirlScout gs = new GirlScout("Jenny", "Alba);

            Console.WriteLine(res);
            Console.WriteLine(gs);

            res.MakeSale(1000000);
            gs.MakeSale(8);
            Console.WriteLine();

            Console.WriteLine(res);
            Console.WriteLine(gs);

            res.MakeSale(2324213);
            gs.MakeSale(2);
            Console.WriteLine();

            Console.WriteLine(res);
            Console.WriteLine(gs);
      
        }
}
}
-----------------------------------------------------------
//Salesperson.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalespersonDemo
{
    abstract class Salesperson
    {
        private string _firstName;
        private string _lastName;

        public Salesperson(string first, string last)
        {
            this.FirstName = first;
            this.LastName = last;
        }

        public string FirstName
        {
            get
            {
                return this._firstName;
            }
            set
            {
                this._firstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return this._lastName;
            }
            set
            {
                this._lastName = value;
            }
        }

        public string GetFullName()
        {
            return this.FirstName + " " + this.LastName;
        }

        public override string ToString()
        {
            return string.Format("{0} ----------------------- Full Name: {1} ",
                this.GetType().ToString().Substring(this.GetType().ToString().IndexOf(".") + 1), this.GetFullName());
        }
    }
}
-----------------------------------------------------------------------------------
//RealEstateSalesperson.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalespersonDemo
{
    class RealEstateSalesperson : Salesperson, ISellable
    {
        private float _totalValueSold;
        private float _totalCommisionEarned;
        private float _commisionRate;

        public RealEstateSalesperson(string first, string last, float commisionRate) : base(first, last)
        {
            this._totalValueSold = 0;
            this._totalCommisionEarned = 0;
            this._commisionRate = commisionRate;
        }

        public float TotalValueSold
        {
            get
            {
                return this._totalValueSold;
            }
            set
            {
                this._totalValueSold = value;
                this.TotalCommisionEarned = this.TotalValueSold * this.CommisionRate;
            }
        }

        public float TotalCommisionEarned
        {
            get
            {
                return this._totalCommisionEarned;
            }
            set
            {
                this._totalCommisionEarned = value;
            }
        }

        public float CommisionRate
        {
            get
            {
                return this._commisionRate;
            }
            set
            {
                this._commisionRate = value;
            }
        }

        public void MakeSale(int dollarValueForAHouse)
        {
            this.SalesSpeech();
            this.TotalValueSold += dollarValueForAHouse;
        }

        public void SalesSpeech()
        {
            Console.WriteLine("I, " + this.GetFullName() + ", just sold a real estate property!");
        }

        public override string ToString()
        {
            return base.ToString() + string.Format("Total Value Sold: {0:C} Total Commision Earned: {1:C} Commision Rate: {2:p} ",
                this.TotalValueSold, this.TotalCommisionEarned, this.CommisionRate);
        }
    }
}
------------------------------------------------------------------------------------
//GirlScout.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalespersonDemo
{
    class GirlScout : Salesperson, ISellable
    {
        private int _boxesCookiesSold;

        public GirlScout(string first, string last) : base(first, last)
        {
            this.BoxesCookiesSold = 0;
        }

        public int BoxesCookiesSold
        {
            get
            {
                return this._boxesCookiesSold;
            }
            set
            {
                this._boxesCookiesSold = value;
            }
        }

        public void MakeSale(int numBoxes)
        {
            this.SalesSpeech();
            this.BoxesCookiesSold += numBoxes;
        }

        public void SalesSpeech()
        {
            Console.WriteLine("I, " + this.GetFullName() + ", just sold some cookies!");
        }

        public override string ToString()
        {
            return base.ToString() + string.Format("Boxes of Cookes Sold: {0} ", this.BoxesCookiesSold);
        }
    }
}
------------------------------------------------------------------------------------
//ISellable.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalespersonDemo
{
    interface ISellable
    {
        void SalesSpeech();
        void MakeSale(int number);
    }
}