bank-account/inheritance-3/lottery.cs - The class Lottery. | Lecture 7 - slide 29 : 40 Program 5 |
using System; public class Lottery{ private static Random rdm = new Random(unchecked((int)DateTime.Now.Ticks)); private int difficulty; private readonly int winningNumber; private readonly decimal amountWon; private static Lottery uniqueInstance = null; private Lottery(int difficulty){ this.difficulty = difficulty; this.winningNumber = rdm.Next(difficulty); this.amountWon = 500000.00M; } public static Lottery Instance(int difficulty){ if (uniqueInstance == null) uniqueInstance = new Lottery(difficulty); return uniqueInstance; } public int DrawLotteryNumber{ get {return rdm.Next(difficulty);} } public bool IsWinningNumber(int number){ return number == winningNumber; } public decimal AmountWon(int luckyNumber){ decimal res; if (IsWinningNumber(luckyNumber)) res = amountWon; else res = 0.0M; return res; } }