示例#1
0
        static void Main(string[] args)
        {
            InterestCalculator newLoan = new InterestCalculator(500, 5.6, 10, InterestType.compound);

            Console.WriteLine(newLoan.CalculateInterest());

            InterestCalculator newDeposit = new InterestCalculator(2500, 7.2, 15, InterestType.simple);

            Console.WriteLine(newDeposit.CalculateInterest());
        }
        public static void Main()
        {
            // using Func<>
            Func<decimal, decimal, decimal, decimal> GetInterest = GetSimpleInterest;
            Console.WriteLine(Math.Round(GetInterest(500m, 0.056m, 10m), 4));

            GetInterest = GetCompoundInterest;
            Console.WriteLine(Math.Round(GetInterest(2500m, 0.072m, 15m), 4));

            // using delegates and InterestCalculator constructor
            InterestCalculator simple = new InterestCalculator(500m, 0.056m, 10m, GetSimpleInterest);
            Console.WriteLine(Math.Round(simple.Money, 4));

            InterestCalculator compound = new InterestCalculator(2500m, 0.072m, 15m, GetCompoundInterest);
            Console.WriteLine(Math.Round(compound.Money, 4));

        }
示例#3
0
        public static void Main()
        {
            // using Func<>
            Func <decimal, decimal, decimal, decimal> GetInterest = GetSimpleInterest;

            Console.WriteLine(Math.Round(GetInterest(500m, 0.056m, 10m), 4));

            GetInterest = GetCompoundInterest;
            Console.WriteLine(Math.Round(GetInterest(2500m, 0.072m, 15m), 4));

            // using delegates and InterestCalculator constructor
            InterestCalculator simple = new InterestCalculator(500m, 0.056m, 10m, GetSimpleInterest);

            Console.WriteLine(Math.Round(simple.Money, 4));

            InterestCalculator compound = new InterestCalculator(2500m, 0.072m, 15m, GetCompoundInterest);

            Console.WriteLine(Math.Round(compound.Money, 4));
        }
示例#4
0
        public static void Main()
        {
            // using constructor
            InterestCalculator simpleInterestCalc = new InterestCalculator(2500m, 7.2m, 15, GetSimpleInterest);

            Console.WriteLine(simpleInterestCalc);

            InterestCalculator compoundInterestCalc = new InterestCalculator(500m, 5.6m, 10, GetCompoundInterest);

            Console.WriteLine(compoundInterestCalc);

            /*
             * // dont use constructor
             * CalculateInterest calcInterest = new CalculateInterest(GetSimpleInterest);
             * // The result should be rounded to 4 places after the decimal point.
             * Console.WriteLine("{0:F4}", calcInterest(2500m, 7.2m, 15));
             * calcInterest = GetCompoundInterest;
             * Console.WriteLine("{0:F4}", calcInterest(500m, 5.6m, 10));
             */
        }