diff --git a/Lottery/Generator.cs b/Lottery/Generator.cs
index c399367..fcd57bf 100644
--- a/Lottery/Generator.cs
+++ b/Lottery/Generator.cs
@@ -2,6 +2,11 @@
{
internal class Generator
{
+ ///
+ /// Simple algorithm for generating a list of unique numbers of Limits.Count size
+ ///
+ /// Defines the amount of numbers to generate, the max and min values
+ /// The list of numbers is returned sorted in ascending order.
public static List Generate(Limits Limits)
{
List Candidates = Enumerable.Range(Limits.Lower, Limits.Upper).ToList();
diff --git a/Lottery/Lottery.cs b/Lottery/Lottery.cs
index 13671a4..11f3a5a 100644
--- a/Lottery/Lottery.cs
+++ b/Lottery/Lottery.cs
@@ -1,14 +1,33 @@
namespace Lottery
{
- internal class Lottery(Limits limits)
+ internal record Limits(int Count, int Lower, int Upper);
+
+ ///
+ /// Abstract base class for lotteries.
+ ///
+ internal class Lottery
{
- protected Limits Limits => limits;
+ protected virtual Limits Limits => throw new NotImplementedException();
public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Limits))}";
}
- internal class LotteryWithSpecial(Limits limits, Limits specialLimits) : Lottery(limits)
+ ///
+ /// Concrete UKLotto Lottery class.
+ /// Generates six balls from 1 to 59.
+ ///
+ internal class UKLottoLottery : Lottery
{
- protected Limits SpecialLimits => specialLimits;
+ protected override Limits Limits { get; } = new(Count: 6, Lower: 1, Upper: 59);
+ }
+
+ ///
+ /// Abstract base class for Lotteries with Special values.
+ /// It subclasses Lottery.
+ /// SpecialLimits and SpecialIdentifier properties must be overridden.
+ ///
+ internal class LotteryWithSpecial : Lottery
+ {
+ protected virtual Limits SpecialLimits => throw new NotImplementedException();
protected virtual string SpecialIdentifier => throw new NotImplementedException();
public override string Play()
@@ -20,18 +39,36 @@
}
}
- internal class EuroMillionsLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
+ ///
+ /// Concrete class for EuroMillions lottery.
+ /// Generates five balls from 1 to 50 and two lucky stars from 1 to 12.
+ ///
+ internal class EuroMillionsLottery : LotteryWithSpecial
{
+ protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 50);
+ protected override Limits SpecialLimits { get; } = new(Count: 2, Lower: 1, Upper: 12);
protected override string SpecialIdentifier => "Lucky Stars";
}
- internal class SetForLifeLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
+ ///
+ /// Concrete class for SetForLifeLottery lottery.
+ /// Generates five balls from 1 to 47 and one life ball from 1 to 10.
+ ///
+ internal class SetForLifeLottery : LotteryWithSpecial
{
+ protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 47);
+ protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 10);
protected override string SpecialIdentifier => "Life Ball";
}
- internal class ThunderballLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
+ ///
+ /// Concrete class for ThunderballLottery lottery.
+ /// Generates fives balls from 1 to 39 and one thunderball from 1 to 14.
+ ///
+ internal class ThunderballLottery : LotteryWithSpecial
{
+ protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 39);
+ protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 14);
protected override string SpecialIdentifier => "Thunderball";
}
}
diff --git a/Lottery/MainPage.xaml.cs b/Lottery/MainPage.xaml.cs
index 18ea968..e619e51 100644
--- a/Lottery/MainPage.xaml.cs
+++ b/Lottery/MainPage.xaml.cs
@@ -1,14 +1,12 @@
namespace Lottery
{
- internal record Limits(int Count, int Lower, int Upper);
-
public partial class MainPage : ContentPage
{
readonly List Lotteries = [
- new Lottery(limits: new Limits(6, 1, 59)),
- new EuroMillionsLottery(limits: new Limits(5, 1, 50), specialLimits: new Limits(2, 1, 12)),
- new SetForLifeLottery(limits: new Limits(5, 1, 47), specialLimits: new Limits(1, 1, 10)),
- new ThunderballLottery(limits: new Limits(5, 1, 39), specialLimits: new Limits(1, 1, 14))
+ new UKLottoLottery(),
+ new EuroMillionsLottery(),
+ new SetForLifeLottery(),
+ new ThunderballLottery()
];
const KindOfLottery DefaultLottery = KindOfLottery.Uk;
Lottery Lottery;