Part 1 & 2

This commit is contained in:
KäseToatz
2024-09-25 22:24:42 +02:00
commit a33cf50a4c
14 changed files with 382 additions and 0 deletions

23
Buckets.Logic/Bucket.cs Normal file
View File

@ -0,0 +1,23 @@
namespace Buckets.Logic
{
public class Bucket : Container
{
private const int DEFAULT_CAPACITY = 12;
private const int MAX_CAPACITY = 2500;
private const int MIN_CAPACITY = 10;
public Bucket(int content) : base(DEFAULT_CAPACITY, content) {}
public Bucket(int capacity, int content) : base(capacity, content)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(capacity, MAX_CAPACITY, nameof(capacity));
ArgumentOutOfRangeException.ThrowIfLessThan(capacity, MIN_CAPACITY, nameof(capacity));
}
public void Fill(Bucket bucket)
{
Content += bucket.Content;
bucket.Empty();
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,32 @@
namespace Buckets.Logic
{
public abstract class Container
{
private int content;
public int Capacity { get; }
public int Content {get => content; set { ArgumentOutOfRangeException.ThrowIfNegative(value, nameof(Content)); ArgumentOutOfRangeException.ThrowIfGreaterThan(value, Capacity, nameof(Content)); content = value; } }
public Container(int capacity, int content)
{
ArgumentOutOfRangeException.ThrowIfNegative(capacity, nameof(Capacity));
Capacity = capacity;
Content = content;
}
public void Fill(int amount)
{
Content += amount;
}
public void Empty(int amount)
{
Content -= amount;
}
public void Empty()
{
Content = 0;
}
}
}

View File

@ -0,0 +1,7 @@
namespace Buckets.Logic
{
public class OilBarrel(int content) : Container(CAPACITY, content)
{
public const int CAPACITY = 159;
}
}

View File

@ -0,0 +1,15 @@
namespace Buckets.Logic
{
public class Rainbarrel : Container
{
private readonly int[] ALLOWED_CAPACITIES = [80, 100, 120];
public Rainbarrel(int capacity, int content) : base(capacity, content)
{
if (!ALLOWED_CAPACITIES.Contains(capacity))
{
throw new ArgumentException($"Capacity must be one of the following values: {string.Join(", ", ALLOWED_CAPACITIES)}.");
}
}
}
}