Question: using System; using System.Collections.Generic; public interface ITeachable { void Teach ( ) ; } public interface IAdmin { void Administrate ( ) ; } public

using System;
using System.Collections.Generic;
public interface ITeachable
{
void Teach();
}
public interface IAdmin
{
void Administrate();
}
public enum ResearchSpeciality
{
AI,
QuantumComputing,
DataScience,
CyberSecurity
}
public abstract class Staff
{
public string Name { get; set; }
public decimal Salary { get; set; }
public Staff(string name, decimal salary)
{
Name = name;
Salary = salary;
}
}
public class Dean : Staff, ITeachable, IAdmin
{
public Dean(string name, decimal salary) : base(name, salary){}
public void Teach()
{
Console.WriteLine("Dean is teaching.");
}
public void Administrate()
{
Console.WriteLine("Dean is administrating.");
}
}
public class Professor : Staff, ITeachable
{
public string Class { get; set; }
public Professor(string name, decimal salary, string className) : base(name, salary)
{
Class = className;
}
public void Teach()
{
Console.WriteLine("Professor is teaching.");
}
}
public class Administrator : Staff, IAdmin
{
public Administrator(string name, decimal salary) : base(name, salary){}
public void Administrate()
{
Console.WriteLine("Administrator is administrating.");
}
}
public class Researcher : Staff, ITeachable
{
public ResearchSpeciality Speciality { get; set; }
public Researcher(string name, decimal salary, ResearchSpeciality speciality) : base(name, salary)
{
Speciality = speciality;
}
public void Teach()
{
Console.WriteLine("Researcher is teaching.");
}
}
public class Department
{
public string Name { get; set; }
public List Staff { get; set; }
public Department(string name)
{
Name = name;
Staff = new List();
}
}
public class University
{
public List Departments { get; set; }
public University()
{
Departments = new List
{
new Department("Math"),
new Department("English"),
new Department("Geography"),
new Department("Computer Science")
};
// Adding some default staff to each department
Departments[0].Staff.Add(new Dean("Dr. Smith", 120000));
Departments[0].Staff.Add(new Professor("Prof. Johnson", 90000, "Calculus"));
Departments[0].Staff.Add(new Administrator("Ms. Brown", 60000));
Departments[0].Staff.Add(new Researcher("Dr. White", 80000, ResearchSpeciality.AI));
// Adding default staff to Geography department to avoid index out of range error
Departments[2].Staff.Add(new Dean("Dr. Green", 110000));
Departments[2].Staff.Add(new Professor("Prof. Blue", 85000, "Geography 101"));
Departments[2].Staff.Add(new Administrator("Mr. Yellow", 55000));
Departments[2].Staff.Add(new Researcher("Dr. Red", 75000, ResearchSpeciality.DataScience));
}
}
public class Program
{
public static void Main()
{
var u = new University();
// Accessing a valid index in Geography department
Console.WriteLine(u.Departments[2].Staff[3].Name);
// Adding a new staff member to English department
u.Departments[1].Staff.Add(new Researcher("Andy",75000, ResearchSpeciality.DataScience));
// Additional test code
foreach (var department in u.Departments)
{
Console.WriteLine($"Department: {department.Name}");
foreach (var staff in department.Staff)
{
Console.WriteLine($"Staff: {staff.Name}, Salary: {staff.Salary}");
if (staff is ITeachable teachable)
{
teachable.Teach();
}
if (staff is IAdmin admin)
{
admin.Administrate();
}
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!