In C# Write an abstract class called StaffMember that has two auto-implemented s
ID: 3774687 • Letter: I
Question
In C#
Write an abstract class called StaffMember that has two auto-implemented string properties called Name and Phone, a two-argument constructor that sets those two property values, a ToString() method that returns a string with those two property values preceded by "Name: " in front of the Name value, and "Phone: " in front of the Phone value, on separate lines. And create an abstract method called Pay() that returns a decimal.
Below the first class, write another class called Volunteer which inherits from StaffMember and has no additional fields. It has a two-argument constructor that sets the Name and Phone properties, a Pay() method that just returns zero, and a ToString() method that returns the word "Volunteer: " followed by the ToString() of its base class.
And, lastly, write a class called Employee which inherits from StaffMember and has an additional protected decimal variablecalled salary and decimal property called Salary. The Salary property is not auto-implemented and its value cannot be negative. Employee has a three-argument constructor that sets the Name, Phone and Salary properties. It also has a Pay()method that returns the value of the Salary property, and a ToString() method that returns the word "Employee: " followed by the ToString() of its base class, followed on a separate line by the word "Pay: ", followed by the value of the Salary property formatted as a currency.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Volunteer emp = new Volunteer("123", "khrv");
var a= emp.ToString();
Console.WriteLine(a);
}
public abstract class StaffMember
{
string Phone, Name;
public StaffMember(string phone, string name)
{
Phone = phone;
Name = name;
}
public string ToString(string phone, string name)
{
return "Name:" + name + @"
Phone:" + Phone;
}
public abstract decimal Pay();
}
class Volunteer : StaffMember
{
string Phone, Name;
public Volunteer(string phone, string name):base(phone,name)
{
Phone = phone;
Name = name;
}
public override decimal Pay()
{
return 0;
}
public string ToString()
{
return "Volunteer:" + base.ToString(Phone, Name);
}
}
class Employee : StaffMember
{
// sealed decimal salary;
decimal Salary;
string Phone, Name;
public Employee(string phone, string name, decimal _salary)
: base(phone, name)
{
Phone = phone;
Name = name;
Salary = _salary;
}
public override decimal Pay()
{
return Salary;
}
public string ToString()
{
return "Employee:" + base.ToString(Phone, Name) + @"
Pay:" + Salary;
}
}
}
}
Thank you for asking CHEGG.