namespace Lottery { internal record Sample(int Lower, int Upper, int Count); /// /// Abstract base class for lotteries. /// Sample property must be overridden. /// internal abstract class Lottery { protected virtual Sample Sample => throw new NotImplementedException(); public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Sample))}"; } /// /// Concrete Lotto Lottery class. /// Generates six balls from 1 to 59. /// internal class LottoLottery : Lottery { protected override Sample Sample { get; } = new(Lower: 1, Upper: 59, Count: 6); } /// /// Abstract base class for Lotteries with Special values. /// It subclasses Lottery. /// SpecialSample and SpecialIdentifier properties must be overridden. /// internal abstract class LotteryWithSpecial : Lottery { protected virtual Sample SpecialSample => throw new NotImplementedException(); protected virtual string SpecialIdentifier => throw new NotImplementedException(); public override string Play() { return string.Join("\n", [ $"Numbers: {string.Join(", ", Generator.Generate(Sample))}", $"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialSample))}", ]); } } /// /// 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 Sample Sample { get; } = new(Lower: 1, Upper: 50, Count: 5); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 12, Count: 2); protected override string SpecialIdentifier => "Lucky Stars"; } /// /// 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 Sample Sample { get; } = new(Lower: 1, Upper: 47, Count: 5); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 10, Count: 1); protected override string SpecialIdentifier => "Life Ball"; } /// /// 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 Sample Sample { get; } = new(Lower: 1, Upper: 39, Count: 5); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 14, Count: 1); protected override string SpecialIdentifier => "Thunderball"; } /// /// Concrete class for PowerballLottery lottery. /// Generates five balls from 1 to 69 and one powerball from 1 to 26. /// internal class PowerballLottery : LotteryWithSpecial { protected override Sample Sample { get; } = new(Lower: 1, Upper: 69, Count: 5); protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 26, Count: 1); protected override string SpecialIdentifier => "Powerball"; } }