Hi
I have the following class to write, with respective methods and such(see below).
The script I have written so far is also attached. I am battling with two parts of this question. I'd like to include a test class to see whether this works but don't know how to override the protected fields so that I can pass properties to my analyst or programmer class.
Lastly, I have no idea how the ToString() method works to apply it to the script as the question asks : "Now override the ToString method to display the employee's information, e.g.: Programmer (Senior): John Doe (7402293945084) ".
I have tried all sorts of different ways of doing this but it's kinda like trying to find a needle in a haystack. Any help would be appreciated.
I have the following class to write, with respective methods and such(see below).
The script I have written so far is also attached. I am battling with two parts of this question. I'd like to include a test class to see whether this works but don't know how to override the protected fields so that I can pass properties to my analyst or programmer class.
Lastly, I have no idea how the ToString() method works to apply it to the script as the question asks : "Now override the ToString method to display the employee's information, e.g.: Programmer (Senior): John Doe (7402293945084) ".
I have tried all sorts of different ways of doing this but it's kinda like trying to find a needle in a haystack. Any help would be appreciated.
Code:
using System; abstract public class Employee { protected string name; protected string idNumber; protected int experience; public Employee() { } public Employee(string strName, string strIDNumber) { name = strName; idNumber = strIDNumber; } public abstract string Evaluate(); abstract public int Experience { get; set; } } public class Programmer : Employee { int count = 0; string PSenior = "Senior"; string PJunior = "Junior"; public override int Experience { get { for (count = 0; count <= 10; count++); return experience; } set { experience = value; count = count + 1; } } public override string Evaluate() { if (experience > 5) { return PSenior; } else { return PJunior; } } } public class Analyst : Employee { int count = 0; string ASenior = "Senior"; string AJunior = "Junior"; public override int Experience { get { for (count = 0; count <= 20; count++); return experience; } set { experience = value; count = count + 1; } } public override string Evaluate() { if (experience > 12) { return ASenior; } else { return AJunior; } } } public class Test { public static void Main() { Analyst myAnalyst = new Analyst("John Doe", "7402293945084", 5); // I'd like to test these properties Console.WriteLine("phew, lets see my analysts name: ", myAnalyst.name()); Console.WriteLine("his idNumber: ", myAnalyst.idNumber()); Console.WriteLine("and the classification from the evaluate method: ", myAnalyst.Evaluate()); Console.WriteLine("which was based on his experience level of: " + experience); } }
Comment