C# Q8) Write an abstract class called StaffMember that has two auto-implemented
ID: 3766408 • Letter: C
Question
C#
Q8)
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 variable called 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;
namespace StaffMember1
{
class StaffMember
{
String Name, Phone;
StaffMember(String n, String p)
{
Name = n;
Phone = p;
}
String[] ToString()
{
String s = "Name:" + Name;
String s1 = "Phone:" + Phone;
return new[] { s, s1 };
}
decimal Pay();
}
class Volunteer : StaffMember
{
Volunteer(String n, String p)
{
Name = n;
Phone = p;
}
String ToString()
{
return ("Volunteer");
}
decimal Pay()
{
return 0;
}
}
class Employee : StaffMember
{
protected decimal salary;
public decimal Salary;
public Employee(String n, String p, decimal s)
{
}
decimal Pay()
{
return Salary;
}
String ToString()
{
String s = "Pay:" + Salary;
return (s);
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.