diff --git a/Mosaic/Company.cs b/Mosaic/Company.cs index 96a8909..28e57ae 100644 --- a/Mosaic/Company.cs +++ b/Mosaic/Company.cs @@ -22,7 +22,11 @@ public sealed class Company public Company(string name, decimal m2Price, decimal hourlyWage, int profitMarginPercent, Worker[] workers) { - // TODO + Name = name; + _m2Price = m2Price; + _hourlyWage = hourlyWage; + _profitMargin = profitMarginPercent; + _workers = workers; } /// @@ -39,6 +43,7 @@ public sealed class Company public decimal GetCostEstimate(TilePattern pattern) { // TODO + return 0; } /// @@ -50,6 +55,30 @@ public sealed class Company /// Number of tiles this company is able to place per hour private double CalcPiecesPerHour(PatternStyle patternStyle) { - // TODO + 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; } } \ No newline at end of file diff --git a/Mosaic/Tile.cs b/Mosaic/Tile.cs index a4a4652..7cabe66 100644 --- a/Mosaic/Tile.cs +++ b/Mosaic/Tile.cs @@ -5,5 +5,62 @@ /// public sealed class Tile { - // TODO + private readonly TileStyle _style; + private readonly int _width; + private readonly int _height; + public readonly int Area; + + public Tile(TileStyle style, int width, int height) + { + _style = style; + _width = width; + _height = height; + Area = width * height; + } + + public decimal CalcProductionCost() + { + decimal pricePerCm = 0.016M; + + decimal sizeFactor = 1; + switch (Area) + { + case < 100: + sizeFactor = 1.5M; + break; + case < 400: + sizeFactor = 1.2M; + break; + case > 2500: + if (Area > 8100) + { + sizeFactor = 1.8M; + break; + } + sizeFactor = 1.6M; + break; + } + + decimal styleFactor = 1; + switch (_style) + { + case TileStyle.Raw: + styleFactor = 0.8M; + break; + case TileStyle.FancyColor: + styleFactor = 1.1M; + break; + case TileStyle.SimplePattern: + styleFactor = 1.25M; + break; + case TileStyle.Ornate: + styleFactor= 2.3M; + break; + } + + decimal areaInCm = Area / 100M; + decimal cost = areaInCm * pricePerCm * sizeFactor * styleFactor; + + return cost; + } } \ No newline at end of file diff --git a/Mosaic/TilePattern.cs b/Mosaic/TilePattern.cs index 1632629..33376b7 100644 --- a/Mosaic/TilePattern.cs +++ b/Mosaic/TilePattern.cs @@ -5,5 +5,39 @@ /// public class TilePattern { - // TODO + private readonly Tile[] _tiles; + public readonly PatternStyle Style; + + public double Area + { + get + { + double area = 0; + foreach (var tile in _tiles) + { + area += tile.Area; + } + + return area / 1000000; + } + } + + public int Pieces => _tiles.Length; + + public TilePattern(PatternStyle style, Tile[] tiles) + { + Style = style; + _tiles = tiles; + } + + public decimal CalcProductionCost() + { + decimal productionCost = 0; + foreach (var tile in _tiles) + { + productionCost += tile.CalcProductionCost(); + } + + return productionCost; + } } \ No newline at end of file