mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-04-27 03:09:37 +02:00
add csharp version to the exercice
This commit is contained in:
20
csharp/TheatricalPlayersRefactoringKata/Invoice.cs
Normal file
20
csharp/TheatricalPlayersRefactoringKata/Invoice.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TheatricalPlayersRefactoringKata
|
||||
{
|
||||
public class Invoice
|
||||
{
|
||||
private string _customer;
|
||||
private List<Performance> _performances;
|
||||
|
||||
public string Customer { get => _customer; set => _customer = value; }
|
||||
public List<Performance> Performances { get => _performances; set => _performances = value; }
|
||||
|
||||
public Invoice(string customer, List<Performance> performance)
|
||||
{
|
||||
this._customer = customer;
|
||||
this._performances = performance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
csharp/TheatricalPlayersRefactoringKata/Performance.cs
Normal file
18
csharp/TheatricalPlayersRefactoringKata/Performance.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace TheatricalPlayersRefactoringKata
|
||||
{
|
||||
public class Performance
|
||||
{
|
||||
private string _playID;
|
||||
private int _audience;
|
||||
|
||||
public string PlayID { get => _playID; set => _playID = value; }
|
||||
public int Audience { get => _audience; set => _audience = value; }
|
||||
|
||||
public Performance(string playID, int audience)
|
||||
{
|
||||
this._playID = playID;
|
||||
this._audience = audience;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
16
csharp/TheatricalPlayersRefactoringKata/Play.cs
Normal file
16
csharp/TheatricalPlayersRefactoringKata/Play.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace TheatricalPlayersRefactoringKata
|
||||
{
|
||||
public class Play
|
||||
{
|
||||
private string _name;
|
||||
private string _type;
|
||||
|
||||
public string Name { get => _name; set => _name = value; }
|
||||
public string Type { get => _type; set => _type = value; }
|
||||
|
||||
public Play(string name, string type) {
|
||||
this._name = name;
|
||||
this._type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
csharp/TheatricalPlayersRefactoringKata/StatementPrinter.cs
Normal file
52
csharp/TheatricalPlayersRefactoringKata/StatementPrinter.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace TheatricalPlayersRefactoringKata
|
||||
{
|
||||
public class StatementPrinter
|
||||
{
|
||||
public string Print(Invoice invoice, Dictionary<string, Play> plays)
|
||||
{
|
||||
var totalAmount = 0;
|
||||
var volumeCredits = 0;
|
||||
var result = string.Format("Statement for {0}\n", invoice.Customer);
|
||||
CultureInfo cultureInfo = new CultureInfo("en-US");
|
||||
|
||||
foreach(var perf in invoice.Performances)
|
||||
{
|
||||
var play = plays[perf.PlayID];
|
||||
var thisAmount = 0;
|
||||
switch (play.Type)
|
||||
{
|
||||
case "tragedy":
|
||||
thisAmount = 40000;
|
||||
if (perf.Audience > 30) {
|
||||
thisAmount += 1000 * (perf.Audience - 30);
|
||||
}
|
||||
break;
|
||||
case "comedy":
|
||||
thisAmount = 30000;
|
||||
if (perf.Audience > 20) {
|
||||
thisAmount += 10000 + 500 * (perf.Audience - 20);
|
||||
}
|
||||
thisAmount += 300 * perf.Audience;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown type: " + play.Type);
|
||||
}
|
||||
// add volume credits
|
||||
volumeCredits += Math.Max(perf.Audience - 30, 0);
|
||||
// add extra credit for every ten comedy attendees
|
||||
if ("comedy" == play.Type) volumeCredits += (int)Math.Floor((decimal)perf.Audience / 5);
|
||||
|
||||
// print line for this order
|
||||
result += String.Format(cultureInfo, " {0}: {1:C} ({2} seats)\n", play.Name, Convert.ToDecimal(thisAmount / 100), perf.Audience);
|
||||
totalAmount += thisAmount;
|
||||
}
|
||||
result += String.Format(cultureInfo, "Amount owed is {0:C}\n", Convert.ToDecimal(totalAmount / 100));
|
||||
result += String.Format("You earned {0} credits\n", volumeCredits);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user