interface IHourly
{
double HourlyRate { get; set; }
}
interface ISalery
{
int Salery { get; set; }
double Bonus { get; }
}
class Person
{
static int
runningId = 0;
public int Id { get; } = runningId++;
public string Name { get; set; }
public override string
ToString() => $"{Id}) {Name}";
}
class Employee : Person, IHourly
{
public double
HourlyRate { get; set; }
public override string
ToString() => $"{base.ToString()} ${HourlyRate * 40 * 52}";
}
class Partner : Person, ISalery
{
public int Salery {
get; set; }
public double Bonus { get => 1.1; }
public override string
ToString() => $"{base.ToString()} ${Salery * Bonus}";
}
class Program
{
static void Main(string[] args)
{
var staffFactory = new StaffFactory();
var data = new [] { "Pawel
$100000", "Magda
$150000", "Marin
$50.00", "Bryne $45.53" };
}
}
class StaffFactory
{
public Person ParseStaff(string data)
{
var dataValues = data.Split(' ');
dataValues[1] =
dataValues[1].TrimStart('$');
double wage;
int salery;
if (int.TryParse(dataValues[1],
out salery))
return new Partner
{ Name = dataValues[0], Salery = salery };
else if (double.TryParse(dataValues[1], out wage))
return new Employee
{ Name = dataValues[0], HourlyRate = wage };
return null;
}
}
class Program
{
static void Main(string[] args)
{
var staffFactory = new StaffFactory();
var data = new string[] { "Pawel
$100000", "Magda
$150000", "Marin
$50.00", "Bryn $45.53" };
foreach (var d in data)
Console.WriteLine(staffFactory.ParseStaff(d).ToString());
}
}