Beispiel #1
0
        public static void Run()
        {
            WriteLine("Calculate this years avarage expenses and earnings. Check your savings rate");

            void ExampleCalculate()
            {
                WriteLine("Example Calculation:");
                decimal expenses         = 100_704.1m;
                decimal earnings         = 246_585m;
                var     savingsCalculate = new SavingsCalculate(expenses, earnings);
                var     formatter        = new SavingsCalculateFormatter(savingsCalculate, new RoundDecimals_2());

                WriteLine(formatter.FormatForConsole());
                WriteLine("");
            }

            ExampleCalculate();

            try {
                WriteLine("What are total expenses?");
                decimal expenses = Convert.ToDecimal(ReadLine());
                WriteLine("What are total earnings?");
                decimal earnings         = Convert.ToDecimal(ReadLine());
                var     savingsCalculate = new SavingsCalculate(expenses, earnings);
                var     formatter        = new SavingsCalculateFormatter(savingsCalculate, new RoundDecimals_2());
                WriteLine(formatter.FormatForConsole());
            } catch (Exception e) {
                WriteLine(e.Message);
                Run();
            }
        }
Beispiel #2
0
        public SavingsCalculateFormatter(SavingsCalculate savingsCalculate, IToDecimals decimalFormat)
        {
            DecimalFormat = decimalFormat;

            Expenses    += DecimalFormat.DecimalRound(savingsCalculate.Expenses);
            Earnings    += DecimalFormat.DecimalRound(savingsCalculate.Earnings);
            AvgExpenses += DecimalFormat.DecimalRound(savingsCalculate.AvgExpenses());
            AvgEarnings += DecimalFormat.DecimalRound(savingsCalculate.AvgEarnings());
            SavingsRate += DecimalFormat.DecimalRound(savingsCalculate.SavingsRate());
        }