namespace Mosaic; /// /// Represents a flooring company /// public sealed class Company { private const int DefaultPiecesPerHour = 25; private readonly decimal _hourlyWage; private readonly decimal _m2Price; private readonly int _profitMargin; private readonly Worker[] _workers; /// /// Constructs a new instance based on the supplied configuration. /// /// The name of the company /// Base price per m2 of floor, independent of pattern type /// Hourly wage of each worker (paid by customer) /// Profit margin put on top of the production cost of the tiles /// Array of the company's employees public Company(string name, decimal m2Price, decimal hourlyWage, int profitMarginPercent, Worker[] workers) { Name = name; _m2Price = m2Price; _hourlyWage = hourlyWage; _profitMargin = profitMarginPercent; _workers = workers; } /// /// Gets the name of the company /// public string Name { get; } /// /// Calculates how much this specific company would charge when tasked with executing the /// supplied pattern. This includes production cost as well as work costs. /// /// Pattern to create /// Cost estimate for the supplied pattern public decimal GetCostEstimate(TilePattern pattern) { double piecesPerHour = CalcPiecesPerHour(pattern.Style); double hours = pattern.Pieces / piecesPerHour; decimal productionCost = pattern.CalcProductionCost(); decimal workCost = (decimal)hours * _hourlyWage * _workers.Length; decimal basePrice = (decimal)pattern.Area * _m2Price; decimal totalCost = basePrice + productionCost + workCost + (productionCost * _profitMargin / 100); return Math.Ceiling(totalCost); } /// /// Calculates how many pieces the workers of this company (together) are able to place per hour. /// This takes into account the complexity of the pattern as well as the working speed of /// each employee. /// /// Defines if the pattern is simple or complex /// Number of tiles this company is able to place per hour private double CalcPiecesPerHour(PatternStyle patternStyle) { double piecesPerHour = 0; for (int i = 0; i < _workers.Length; i++) { double pieces = DefaultPiecesPerHour; // pieces based on worker's speed if (_workers[i].WorkSpeed == WorkSpeed.Fast) { pieces += 5; } else if (_workers[i].WorkSpeed == WorkSpeed.Slow) { pieces -= 5; } // pieces based on pattern complexity if (patternStyle == PatternStyle.Complex) { pieces /= 2; } piecesPerHour += pieces; } return piecesPerHour; } }