Implemented the program

This commit is contained in:
MarcUs7i 2025-02-27 17:11:51 +01:00
parent 532c17ddd3
commit 8706b1e0d0
4 changed files with 29 additions and 16 deletions

View file

@ -15,10 +15,9 @@ public abstract class Employee
/// <param name="department">Department the employee works at</param>
protected Employee(string name, Gender gender, string department)
{
Name = string.Empty;
Gender = Gender.Divers;
Department = string.Empty;
// TODO
Name = name;
Gender = gender;
Department = department;
}
/// <summary>
@ -29,7 +28,14 @@ public abstract class Employee
get => _name;
private init
{
// TODO
if(value.Length < 2 || !char.IsUpper(value[0]) || char.IsDigit(value[0]))
{
_name = "ERROR";
}
else
{
_name = value;
}
}
}
@ -54,8 +60,14 @@ public abstract class Employee
/// <returns>String representation of the employee</returns>
public override string ToString()
{
// TODO
return string.Empty;
string result = $"My name is {Name}";
if (Gender != Gender.Divers)
{
string genderString = $"{Gender}";
result += $", I identify as {genderString.ToLower()}";
}
result += $" and I work at the department {Department}";
return result;
}
}

View file

@ -19,7 +19,7 @@ public sealed class Manager : OfficeEmployee
/// <summary>
/// Gets the actual salary for the manger, which is higher than the base salary
/// </summary>
public override decimal Salary => -1M; // TODO
public override decimal Salary => base.Salary * 1.2M;
public override string ToString() => string.Empty; // TODO
public override string ToString() => $"My name is {Name} and I'm head of the {Department} department";
}

View file

@ -16,10 +16,10 @@ public class OfficeEmployee : Employee
public OfficeEmployee(string name, Gender gender, string department,
decimal monthlySalary) : base(name, gender, department)
{
// TODO
Salary = Math.Max(0M, monthlySalary);
}
public override decimal Salary { get; }
public override string ToString() => string.Empty; // TODO
public override string ToString() => $"{base.ToString()} as an employee";
}

View file

@ -34,7 +34,8 @@ public sealed class Worker : Employee
public Worker(string name, Gender gender, string department, double hours, decimal hourlyWage)
: this(name, gender, department)
{
// TODO
Hours = hours;
HourlyWage = hourlyWage;
}
/// <summary>
@ -44,7 +45,7 @@ public sealed class Worker : Employee
public double Hours
{
get => _hours;
set => _hours = -1D; // TODO
set => _hours = Math.Clamp(value, 0, MaxMonthlyWorkHours);
}
/// <summary>
@ -54,10 +55,10 @@ public sealed class Worker : Employee
public decimal HourlyWage
{
get => _hourlyWage;
set => _hourlyWage = -1M; // TODO
set => _hourlyWage = Math.Max(0, value);
}
public override decimal Salary => -1M; // TODO
public override decimal Salary => (decimal)Hours * HourlyWage;
public override string ToString() => string.Empty; // TODO
public override string ToString() => $"{base.ToString()} as a worker";
}