// Exercise 2: abstract classes, interfaces, and default interface methods // // Implement: // - abstract class Employee with abstract MonthlyPay() and a concrete // AnnualPay() that's computed FROM MonthlyPay() (polymorphically). // - interface IBenefits with a default-implemented Describe() method, // and one abstract member HasHealthInsurance. // - Manager : Employee, IBenefits using System; interface IBenefits { bool HasHealthInsurance { get; } string Describe() => HasHealthInsurance ? "has health insurance" : "no health insurance"; } abstract class Employee { public abstract decimal MonthlyPay(); public decimal AnnualPay() { // TODO: return MonthlyPay() * 12. Must call the polymorphic // MonthlyPay() so subclass overrides are respected. throw new NotImplementedException(); } } class Manager : Employee, IBenefits { public decimal BaseSalary { get; init; } public bool HasHealthInsurance => true; public override decimal MonthlyPay() { // TODO: return BaseSalary throw new NotImplementedException(); } } class Program { static void Main() { int pass = 0, total = 0; Employee mgr = new Manager { BaseSalary = 5000m }; total++; if (mgr.AnnualPay() == 60000m) { Console.WriteLine("PASS: AnnualPay uses overridden MonthlyPay"); pass++; } else Console.WriteLine("FAIL: AnnualPay uses overridden MonthlyPay, got " + mgr.AnnualPay()); IBenefits benefits = new Manager { BaseSalary = 5000m }; total++; if (benefits.Describe() == "has health insurance") { Console.WriteLine("PASS: default interface method works"); pass++; } else Console.WriteLine("FAIL: default interface method works, got " + benefits.Describe()); Console.WriteLine($"--- {pass}/{total} checks passed ---"); } }