Implemented the program
This commit is contained in:
parent
532c17ddd3
commit
8706b1e0d0
4 changed files with 29 additions and 16 deletions
|
|
@ -15,10 +15,9 @@ public abstract class Employee
|
||||||
/// <param name="department">Department the employee works at</param>
|
/// <param name="department">Department the employee works at</param>
|
||||||
protected Employee(string name, Gender gender, string department)
|
protected Employee(string name, Gender gender, string department)
|
||||||
{
|
{
|
||||||
Name = string.Empty;
|
Name = name;
|
||||||
Gender = Gender.Divers;
|
Gender = gender;
|
||||||
Department = string.Empty;
|
Department = department;
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -29,7 +28,14 @@ public abstract class Employee
|
||||||
get => _name;
|
get => _name;
|
||||||
private init
|
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>
|
/// <returns>String representation of the employee</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
// TODO
|
string result = $"My name is {Name}";
|
||||||
return string.Empty;
|
if (Gender != Gender.Divers)
|
||||||
|
{
|
||||||
|
string genderString = $"{Gender}";
|
||||||
|
result += $", I identify as {genderString.ToLower()}";
|
||||||
|
}
|
||||||
|
result += $" and I work at the department {Department}";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public sealed class Manager : OfficeEmployee
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the actual salary for the manger, which is higher than the base salary
|
/// Gets the actual salary for the manger, which is higher than the base salary
|
||||||
/// </summary>
|
/// </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";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ public class OfficeEmployee : Employee
|
||||||
public OfficeEmployee(string name, Gender gender, string department,
|
public OfficeEmployee(string name, Gender gender, string department,
|
||||||
decimal monthlySalary) : base(name, gender, department)
|
decimal monthlySalary) : base(name, gender, department)
|
||||||
{
|
{
|
||||||
// TODO
|
Salary = Math.Max(0M, monthlySalary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override decimal Salary { get; }
|
public override decimal Salary { get; }
|
||||||
|
|
||||||
public override string ToString() => string.Empty; // TODO
|
public override string ToString() => $"{base.ToString()} as an employee";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ public sealed class Worker : Employee
|
||||||
public Worker(string name, Gender gender, string department, double hours, decimal hourlyWage)
|
public Worker(string name, Gender gender, string department, double hours, decimal hourlyWage)
|
||||||
: this(name, gender, department)
|
: this(name, gender, department)
|
||||||
{
|
{
|
||||||
// TODO
|
Hours = hours;
|
||||||
|
HourlyWage = hourlyWage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -44,7 +45,7 @@ public sealed class Worker : Employee
|
||||||
public double Hours
|
public double Hours
|
||||||
{
|
{
|
||||||
get => _hours;
|
get => _hours;
|
||||||
set => _hours = -1D; // TODO
|
set => _hours = Math.Clamp(value, 0, MaxMonthlyWorkHours);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,10 +55,10 @@ public sealed class Worker : Employee
|
||||||
public decimal HourlyWage
|
public decimal HourlyWage
|
||||||
{
|
{
|
||||||
get => _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";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue