Part 1 & 2
This commit is contained in:
23
Buckets.Logic/Bucket.cs
Normal file
23
Buckets.Logic/Bucket.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
9
Buckets.Logic/Buckets.Logic.csproj
Normal file
9
Buckets.Logic/Buckets.Logic.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
32
Buckets.Logic/Container.cs
Normal file
32
Buckets.Logic/Container.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
7
Buckets.Logic/OilBarrel.cs
Normal file
7
Buckets.Logic/OilBarrel.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Buckets.Logic
|
||||
{
|
||||
public class OilBarrel(int content) : Container(CAPACITY, content)
|
||||
{
|
||||
public const int CAPACITY = 159;
|
||||
}
|
||||
}
|
15
Buckets.Logic/Rainbarrel.cs
Normal file
15
Buckets.Logic/Rainbarrel.cs
Normal 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)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user