Exemplo n.º 1
0
        private static BalanceClass _instance = null; //Singleton pattern

        public static BalanceClass Instance()         //Lazy Load initiation
        {
            if (_instance == null)
            {
                _instance = new BalanceClass();
            }
            return(_instance);
        }
Exemplo n.º 2
0
 public int GetMonthCountUntilGoalIsReached() //Aplicable only for one goal
 {
     try
     {
         int monthCount;
         List <TraceableBalance> balances = (List <TraceableBalance>)BalanceClass.Instance().GetMonthlyBalances();
         decimal averageBalance           = 0;
         decimal currentSum = 0;
         foreach (var balance in balances) //LINQ greiciau
         {
             currentSum += balance.amount;
         }
         averageBalance = currentSum / balances.Count;
         Goal goal = ParseGoal();
         monthCount = (int)Math.Round((goal.amount - currentSum) / averageBalance);
         return(monthCount);
     }
     catch (Exception e)
     {
         Logger.Instance().Log(e.ToString());
         return(-1);
     }
 }