Beispiel #1
0
        public void TestSimpleInterestWithDays()
        {
            // 1 day simple interest
            double interest = InterestCalculator.calculateSimpleInterest(10000, 10, 1);

            Assert.AreEqual(2.74, interest, DOUBLE_DELTA);

            // 30 days simple accured interest
            interest = InterestCalculator.calculateSimpleInterest(10000, 10, 30);
            Assert.AreEqual(82.19, interest, DOUBLE_DELTA);

            // 365 days simple interest
            interest = InterestCalculator.calculateSimpleInterest(10000, 10, 365);
            Assert.AreEqual(1000, interest, DOUBLE_DELTA);

            // 2 years simple iterest
            interest = InterestCalculator.calculateSimpleInterest(10000, 10, 2 * 365);
            Assert.AreEqual(2000, interest, DOUBLE_DELTA);

            // Wrong inputs
            interest = InterestCalculator.calculateSimpleInterest(0, 0, 0);
            Assert.AreEqual(0, interest, DOUBLE_DELTA);

            interest = InterestCalculator.calculateDailyAccruedInterest(-1000, -10, -1);
            Assert.AreEqual(0, interest, DOUBLE_DELTA);
        }
 public void InterestRates_WhenBalanceIsInvalid_ThrowNullArgumentException(string input)
 {
     // Arange
     InterestCalculator interestRates = new InterestCalculator();
     // Act
     decimal actual = interestRates.GetInterestRate(input);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            double interest = InterestCalculator.calculateInterest(5, 5000.0, 0.10);

            Console.WriteLine("Simple interest:" + interest);
            Console.ReadLine();
        }
 static void Main()
 {
     InterestCalculator simpleInterest = new InterestCalculator(2500, 7.2, 15, GetSimpleInterest);
     Console.WriteLine("{0:0.0000}", simpleInterest.CalculatedInterest);
     InterestCalculator CompoundInterest = new InterestCalculator(500, 5.6, 10, GetCompoundInterest);
     Console.WriteLine("{0:0.0000}", CompoundInterest.CalculatedInterest);
 }
Beispiel #5
0
        public void TestDailyAccruedInterestWithDays()
        {
            // 1 day daily accured iterest
            double interest = InterestCalculator.calculateDailyAccruedInterest(10000, 10, 1);

            Assert.AreEqual(2.74, interest, DOUBLE_DELTA);

            // 30 days / 1 month daily accured iterest
            interest = InterestCalculator.calculateDailyAccruedInterest(10000, 10, 30);
            Assert.AreEqual(82.52, interest, DOUBLE_DELTA);

            // 365 days / 1 year daily accured iterest
            interest = InterestCalculator.calculateDailyAccruedInterest(10000, 10, 365);
            Assert.AreEqual(1051.56, interest, DOUBLE_DELTA);

            // 2 years daily accured iterest
            interest = InterestCalculator.calculateDailyAccruedInterest(10000, 10, 2 * 365);
            Assert.AreEqual(2213.69, interest, DOUBLE_DELTA);


            // Wrong inputs
            interest = InterestCalculator.calculateDailyAccruedInterest(0, 0, 0);
            Assert.AreEqual(0, interest, DOUBLE_DELTA);

            interest = InterestCalculator.calculateDailyAccruedInterest(-1000, -10, -1);
            Assert.AreEqual(0, interest, DOUBLE_DELTA);
        }
Beispiel #6
0
 public ResponseProfile()
 {
     CreateMap <Entities.Agreement, Models.ResponseDto>()
     .ForMember(dest => dest.Name,
                opt => opt.MapFrom(src => $"{src.Customer.FirstName} {src.Customer.LastName}"))
     .ForMember(dest => dest.PersonalId,
                opt => opt.MapFrom(src => src.Customer.PersonalId))
     .ForMember(dest => dest.Id,
                opt => opt.MapFrom(src => src.Id))
     .ForMember(dest => dest.Amount,
                opt => opt.MapFrom(src => src.Amount))
     .ForMember(dest => dest.BaseRateCode,
                opt => opt.MapFrom(src => src.BaseRateCode))
     .ForMember(dest => dest.NewBaseRateCode,
                opt => opt.MapFrom(src => src.NewBaseRateCode))
     .ForMember(dest => dest.Margin,
                opt => opt.MapFrom(src => src.Margin))
     .ForMember(dest => dest.AgreementDuration,
                opt => opt.MapFrom(src => src.AgreementDuration))
     .ForMember(dest => dest.InterestRateForCurrentBaseRate,
                opt => opt.MapFrom(src => InterestCalculator.GetInterestRate(src.BaseRateCode, src.Margin)))
     .ForMember(dest => dest.InterestRateForNewBaseRate,
                opt => opt.MapFrom(src => InterestCalculator.GetInterestRate(src.NewBaseRateCode, src.Margin)))
     .ForMember(dest => dest.InterestRateDifference,
                opt => opt.MapFrom(src => InterestCalculator.GetDifference(src.BaseRateCode, src.NewBaseRateCode, src.Margin)));
 }
        public void TestCase1()
        {
            //Arrange
            decimal bal  = 100m;
            var     visa = new Visa(bal);
            var     mc   = new MasterCard(bal);
            var     disc = new Discover(bal);

            Wallet homersWallet = new Wallet();

            homersWallet.AddCard(visa);
            homersWallet.AddCard(mc);
            homersWallet.AddCard(disc);

            Person homer = new Person("Homer J Simpson", new List <Wallet>()
            {
                homersWallet
            });

            //Act
            decimal interestHomer = InterestCalculator.CalculatePersonSimpleInterest(homer);

            decimal interestVisa       = InterestCalculator.CalculateSimpleInterest(visa.CurrentBalance, visa.InterestRate);
            decimal interestMasterCard = InterestCalculator.CalculateSimpleInterest(mc.CurrentBalance, mc.InterestRate);
            decimal interestDiscover   = InterestCalculator.CalculateSimpleInterest(disc.CurrentBalance, disc.InterestRate);

            //Assert
            Assert.Equal(16m, interestHomer);       //Total simple interest for the person

            Assert.Equal(10m, interestVisa);        //Simple interest per card
            Assert.Equal(5m, interestMasterCard);
            Assert.Equal(1m, interestDiscover);

            Assert.Equal(interestHomer, interestVisa + interestMasterCard + interestDiscover); //Total should equal the sum of all cards
        }
        public void InterestCalculator_Incorrect(int interestPercent, double principleAmount, int yearAmount)
        {
            var calculator = new InterestCalculator();

            calculator.SetInterestPercent(interestPercent);
            var result = calculator.Calculate(principleAmount, yearAmount);
        }
Beispiel #9
0
        public void UT_negative_years_should_throw()
        {
            Exception ex = Assert.Throws <ArgumentException>(() =>
                                                             InterestCalculator.GetFinalBalance(1, 0.05, -10));

            Assert.True(ex.Message.StartsWith("years cannot be negative"));
        }
        static void Main()
        {
            InterestCalculator simpleInterestCalculator = new InterestCalculator(2500m, 0.072m, 15, GetSimpleInterest);
            Console.WriteLine(simpleInterestCalculator.Balance);

            InterestCalculator compoundInterestCalculator = new InterestCalculator(500m, 0.056m, 10, GetCompoundInterest);
            Console.WriteLine(compoundInterestCalculator.Balance);
        }
    static void Main()
    {
        var simpleInterest = new InterestCalculator(500m, 5.6m, 10, GetCompoundInterest);
        Console.WriteLine(simpleInterest);

        var compoundInterest = new InterestCalculator(2500m, 7.2m, 15, GetSimpleInterest);
        Console.WriteLine(compoundInterest);
    }
Beispiel #12
0
    static void Main()
    {
        InterestCalculator calcCompoundInterest = new InterestCalculator(500, 5.6, 10, GetCompoundInterest);
        Console.WriteLine("{0:0.0000}", calcCompoundInterest.TotalMoney);

        InterestCalculator calcSimpleInterest = new InterestCalculator(2500, 7.2, 15, GetSimpleInterest);
        Console.WriteLine("{0:0.0000}", calcSimpleInterest.TotalMoney);       
    }
Beispiel #13
0
            public static void Main()
            {
                InterestCalculator iCalc = new InterestCalculator(500, 5.6m, 10, GetCompoundInterest);
                InterestCalculator iCalc2 = new InterestCalculator(2500,7.2m,15, GetSimpleInterest);

                Console.WriteLine("{0:F3}", iCalc.Result);
                Console.WriteLine("{0:F3}", iCalc2.Result);
            }
Beispiel #14
0
    static void Main()
    {
        var firstSum  = new InterestCalculator(500m, 5.6, 10, GetCompoundInterest);
        var secondSum = new InterestCalculator(2500m, 7.2, 15, GetSimpleInterest);

        Console.WriteLine(firstSum);
        Console.WriteLine(secondSum);
    }
    public static void Main()
    {
        InterestCalculator simpleCalc = new InterestCalculator(2500, 7.2m, 15, InterestCalculator.GetSimpleInterest);
        Console.WriteLine("{0:0.0000}", simpleCalc.PayOutValue);

        InterestCalculator compoundCalc = new InterestCalculator(500, 5.6m, 10, InterestCalculator.GetCompoundInterest);
        Console.WriteLine("{0:0.0000}", compoundCalc.PayOutValue);
    }
Beispiel #16
0
    static void Main()
    {
        InterestCalculator calc = new InterestCalculator(500m, 5.6, 10, InterestCalculator.GetCompoundInterest);

        Console.WriteLine("{0:0.0000}", calc.ResultValue);

        calc = new InterestCalculator(2500m, 7.2, 15, InterestCalculator.GetSimpleInterest);
        Console.WriteLine("{0:0.0000}", calc.ResultValue);
    }
Beispiel #17
0
    static void Main()
    {
        InterestCalculator simpleInterest = new InterestCalculator(2500, 7.2, 15, GetSimpleInterest);

        Console.WriteLine("{0:0.0000}", simpleInterest.CalculatedInterest);
        InterestCalculator CompoundInterest = new InterestCalculator(500, 5.6, 10, GetCompoundInterest);

        Console.WriteLine("{0:0.0000}", CompoundInterest.CalculatedInterest);
    }
    static void Main()
    {
        var firstSum = new InterestCalculator(500m, 5.6, 10, GetCompoundInterest);
        var secondSum = new InterestCalculator(2500m, 7.2, 15, GetSimpleInterest);

        Console.WriteLine(firstSum);
        Console.WriteLine(secondSum);

    }
    static void Main()
    {

        InterestCalculator calc = new InterestCalculator(500m, 5.6, 10, InterestCalculator.GetCompoundInterest);
        Console.WriteLine("{0:0.0000}", calc.ResultValue);

        calc = new InterestCalculator(2500m, 7.2, 15, InterestCalculator.GetSimpleInterest);
        Console.WriteLine("{0:0.0000}", calc.ResultValue);
    }
Beispiel #20
0
    static void Main()
    {
        InterestCalculator simple = new InterestCalculator(500m, 5.6f, 10, GetCompoundInterest);

        Console.WriteLine(simple.MoneyAfterIdexation);
        InterestCalculator compound = new InterestCalculator(2500m, 7.2f, 15, GetSimpleInterest);

        Console.WriteLine(compound.MoneyAfterIdexation);
    }
Beispiel #21
0
    static void Main()
    {
        InterestCalculator calcCompoundInterest = new InterestCalculator(500, 5.6, 10, GetCompoundInterest);

        Console.WriteLine("{0:0.0000}", calcCompoundInterest.TotalMoney);

        InterestCalculator calcSimpleInterest = new InterestCalculator(2500, 7.2, 15, GetSimpleInterest);

        Console.WriteLine("{0:0.0000}", calcSimpleInterest.TotalMoney);
    }
        public void InterestRates_WhenInputedBalanace_ReturnCalculatedInterest()
        {
            // Arange
            InterestCalculator interestRates = new InterestCalculator();
            // Act
            string actual = interestRates.GetInterest("1001");

            // Assert
            Assert.AreEqual("15.02", actual);
        }
        public void InterestRates_WhenBalanaceIsLessThan1000_Return1Percent(string input)
        {
            // Arange
            InterestCalculator interestRates = new InterestCalculator();
            // Act
            decimal actual = interestRates.GetInterestRate(input);

            // Assert
            Assert.AreEqual(1.00m, actual);
        }
    static void Main()
    {
        var simpleInterest = new InterestCalculator(500m, 5.6m, 10, GetCompoundInterest);

        Console.WriteLine(simpleInterest);

        var compoundInterest = new InterestCalculator(2500m, 7.2m, 15, GetSimpleInterest);

        Console.WriteLine(compoundInterest);
    }
        public void InterestRates_WhenBalanceIsBetween10000And50000_Return2point5Percent(string input)
        {
            // Arange
            InterestCalculator interestRates = new InterestCalculator();
            // Act
            decimal actual = interestRates.GetInterestRate(input);

            // Assert
            Assert.AreEqual(2.50m, actual);
        }
Beispiel #26
0
    static void Main()
    {
        InterestCalculator firstInterest = new InterestCalculator(500, 5.6, 10, TypeOfInterestCalculator.GetCompoundInterest);

        Console.WriteLine(firstInterest.ToString());

        InterestCalculator secondInterest = new InterestCalculator(2500, 7.2, 15, TypeOfInterestCalculator.GetSimpleInterest);

        Console.WriteLine(secondInterest.ToString());
    }
    static void Main()
    {
        CalculateInterestDelegate delegateSimpleInterest = new CalculateInterestDelegate(InterestCalculator.GetSimpleInterest);
        InterestCalculator calculateSimpleInterest = new InterestCalculator(2500, 7.2, 15, delegateSimpleInterest);
        Console.WriteLine(calculateSimpleInterest);

        CalculateInterestDelegate delegateCompoundInterest = new CalculateInterestDelegate(InterestCalculator.GetCompoundInterest);
        InterestCalculator calculateCompoundInterest = new InterestCalculator(500, 5.6, 10, delegateCompoundInterest);
        Console.WriteLine(calculateCompoundInterest);
    }
        public void InterestRates_WhenBalanceIsZero_Return0Percent(string input)
        {
            // Arange
            InterestCalculator interestRates = new InterestCalculator();
            // Act
            decimal actual = interestRates.GetInterestRate(input);

            // Assert
            Assert.AreEqual(0.00m, actual);
        }
        public void InterestCalculator_Correct(int interestPercent, double principleAmount, int yearAmount, string expected)
        {
            var calculator = new InterestCalculator();

            calculator.SetInterestPercent(interestPercent);
            var result = calculator.Calculate(principleAmount, yearAmount);

            var expectedResult = expected.Split(',').Select(it => double.Parse(it));

            result.Should().BeEquivalentTo(expectedResult);
        }
Beispiel #30
0
    static void Main(string[] args)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        var simpleInterest = new InterestCalculator(2500m, 7.2, 15, GetSimpleInterest);

        Console.WriteLine(simpleInterest);

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

        Console.WriteLine(compoundInterest);
    }
Beispiel #31
0
        static void Main()
        {
            CalculateInterest simpleInterestDelegate = GetSimpleInterest;
            CalculateInterest comInterestDelegate    = GetCompoundInterest;


            InterestCalculator compoundInterestCalculator = new InterestCalculator(500, 5.6, 10, comInterestDelegate);
            InterestCalculator simpleInterestCalculator   = new InterestCalculator(2500, 7.2, 15, simpleInterestDelegate);

            Console.WriteLine(compoundInterestCalculator);
            Console.WriteLine(simpleInterestCalculator);
        }
    static void Main()
    {
        Func<int, double, int, string> CalculateInterest = GetCompoundInterest;

        InterestCalculator interestCalculator = new InterestCalculator(500, 5.6, 10, CalculateInterest);
        Console.WriteLine(interestCalculator.Result);

        interestCalculator.Sum = 2500;
        interestCalculator.Interest = 7.2;
        interestCalculator.Years = 15;
        interestCalculator.CalculateInterestDelegate = GetSimpleInterest;
        Console.WriteLine(interestCalculator.Result);
    }
        static void Main()
        {
            InterestCalculator.GetInteres g1 = GetSimpleInterest;
            InterestCalculator.GetInteres g2 = GetCompoundInterest;

            var a = new InterestCalculator(2500m, 7.2m, 15, Types.Simple);
            var b = new InterestCalculator(500m, 5.6m, 10, Types.Compound);

            Console.WriteLine(a);
            Console.WriteLine(g1(2500m, 7.2m, 15));
            Console.WriteLine(b);
            Console.WriteLine(g2(500m, 5.6m, 10));
        }
Beispiel #34
0
        public void VistaPactadaTest()
        {
            CalculatorMessage  result;
            InterestCalculator calculator = new InterestCalculator("InversionVistaPactada");

            //Vista Pactada en colones
            result = calculator.calculateInterestPerformance(1200000, 56, Products.MoneyType.Colones);
            Assert.AreEqual(Math.Round(result.FinalBalance, 2), 1209221.33M);

            //Vista Pactada en dólares
            result = calculator.calculateInterestPerformance(8500, 150, Products.MoneyType.Dolares);
            Assert.AreEqual(Math.Round(result.FinalBalance, 2), 8551);
        }
Beispiel #35
0
        public void Should_Read_Bands_And_Return_Correct_Interest()
        {
            var readerFactory = new TextReaderFactory(@"IntegrationTests\test_data\bands.txt");
            var bandsReader   = new CSVBandsReader(readerFactory, "|");

            using (var bandsCache = new BandsCache(bandsReader))
            {
                var interestRateReturner = new InterestRateReturner(bandsCache);
                var interestCalculator   = new InterestCalculator(interestRateReturner);

                Assert.AreEqual(15.02m, interestCalculator.GetAmountOfInterest(1001));
            }
        }
        public void TestCalculateInterestRate()
        {
            double[] values         = { 100, 120.5, 1000.98, 32000, 16500 };
            int[]    months         = { 3, 3, 12, 30, 48 };
            double[] expectedValues = { 103.03, 124.15, 1127.92, 43131.16, 26601.73 };

            var calculator = new InterestCalculator();

            for (var index = 0; index < values.Length; index++)
            {
                Assert.Equal(expectedValues[index], calculator.CalculateInterestRate(values[index], months[index]), 6);
            }
        }
        //[DataRow("4999.99", "74.99")]
        public void CalculateThreePercentInterest(string bankBalance, string interestToBePaid)
        {
            // Arrange.
            var bankBalanceAsDecimal      = decimal.Parse(bankBalance);
            var interestToBePaidAsDecimal = decimal.Parse(interestToBePaid);
            var InterestCalculator        = new InterestCalculator();

            // Act.
            var interestPaid = InterestCalculator.Calculate(bankBalanceAsDecimal);

            // Assert.
            Assert.AreEqual(interestToBePaidAsDecimal, interestPaid);
        }
        public void Return_Total_Annual_Interest_Applicable_Based_On_Amount_Request()
        {
            // Arrange
            var amount  = 200;
            var lenders = new[] { new Lender(100, 0.069m), new Lender(250, 0.075m) };
            IInterestCalculator interestCalculator = new InterestCalculator();
            var expectedInterestedRate             = 0.144m;

            // Act
            var interestRate = interestCalculator.CalculateTotalAnnualInterest(lenders, amount);

            // Assert
            Assert.Equal(expectedInterestedRate, interestRate);
        }
Beispiel #39
0
        public void CertificadoTest()
        {
            CalculatorMessage  result;
            InterestCalculator calculator;

            //Certificado

            calculator = new InterestCalculator("CertificadoDeDeposito");
            result     = calculator.calculateInterestPerformance(2500000, 48, Model.Products.MoneyType.Colones);

            Assert.AreEqual(Math.Round(result.FinalBalance, 2), 2516560.00M); //saldo final
            Assert.AreEqual(result.InterestEarned, 18000);                    // intereses ganados en el plazo
            Assert.AreEqual(result.TaxApplied, 1440);                         // impuesto de la renta
        }
    static void Main()
    {
        CalculateInterest simple = GetSimpleInterest;
        CalculateInterest compound = GetCompoundInterest;

        var compoundInterestCalculator = new InterestCalculator(500, 5.6, 10, compound);
        var simpleInterestCalculator = new InterestCalculator(2500, 7.2, 15, simple);

        double simpleInterest = simpleInterestCalculator.Interest;
        double compoundInterest = compoundInterestCalculator.Interest;

        Console.WriteLine(compoundInterest);
        Console.WriteLine(simpleInterest);
    }
Beispiel #41
0
        public void TestDailyAccruedInterestWithMultipleTransactions()
        {
            List <Transaction> transactions = new List <Transaction>();

            transactions.Add(new Transaction(5000, 5000, TransactionType.Deposit, DateTime.Parse("2015/01/01 09:00:00")));
            transactions.Add(new Transaction(2000, 3000, TransactionType.WithDraw, DateTime.Parse("2015/01/01 10:00:00")));
            transactions.Add(new Transaction(7000, 10000, TransactionType.Deposit, DateTime.Parse("2015/01/01 11:00:00")));

            // 1 day daily accured iterest
            double interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/01/02"), InterestType.COMPOUNDED_DAILY);

            Assert.AreEqual(2.74, interest, DOUBLE_DELTA);

            // 30 days / 1 month daily accured iterest
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/01/31"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(82.52, interest, DOUBLE_DELTA);

            // 60 Days interest
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/03/02"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(165.72, interest, DOUBLE_DELTA);

            // 90 Days interest
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/04/01"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(249.61, interest, DOUBLE_DELTA);

            // Add one more 10K deposit , 30 days after 1st deposit
            transactions.Add(new Transaction(10000, 20000, TransactionType.Deposit, DateTime.Parse("2015/01/31 09:00:00")));

            // 60 Days intetrest (2 months of 10K + 1 month of 10K)
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/03/02"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(165.72 + 82.52, interest, DOUBLE_DELTA);

            // Add one more 10K deposit (2K - 1k + 9k), 60 days after 1st deposit
            transactions.Add(new Transaction(2000, 22000, TransactionType.Deposit, DateTime.Parse("2015/03/02 09:00:00")));
            transactions.Add(new Transaction(1000, 21000, TransactionType.WithDraw, DateTime.Parse("2015/03/02 09:00:00")));
            transactions.Add(new Transaction(9000, 30000, TransactionType.Deposit, DateTime.Parse("2015/03/02 09:00:00")));

            // 60 Days intetrest (new deposit just added shd not be accrued)
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/03/02"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(165.72 + 82.52, interest, DOUBLE_DELTA);

            // 90 Days intetrest (3 months of 10K + 2 month of 10K + 1 month of 10K)
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2015/04/01"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(249.61 + 165.72 + 82.52, interest, DOUBLE_DELTA);


            // Wrong inputs
            interest = InterestCalculator.calculateAccruedInterest(transactions, 10, DateTime.Parse("2014/01/31"), InterestType.COMPOUNDED_DAILY);
            Assert.AreEqual(0, interest, DOUBLE_DELTA);
        }
Beispiel #42
0
        private CalculatorMessage calculoResultado(string pSistemaAhorro,
                                                   string pMonto,
                                                   string pPlazo,
                                                   string pMoneda)
        {
            InterestCalculator calculator = new InterestCalculator(pSistemaAhorro);
            MoneyType          enumMoneda = (MoneyType)Enum.Parse(typeof(MoneyType), pMoneda, true);
            decimal            monto      = decimal.Parse(pMonto);
            int dias = int.Parse(pPlazo);
            //Console.WriteLine(enumMoneda);
            CalculatorMessage resultado = calculator.calculateInterestPerformance(monto, dias, enumMoneda);

            return(resultado);
        }
Beispiel #43
0
    static void Main(string[] args)
    {
        var interestCalculator = new InterestCalculator(500m, 5.6m, 10, GetCompoundInterest);
        Console.WriteLine(interestCalculator);

        var compoundInterest = new InterestCalculator(2500m, 7.2m, 15, GetSimpleInterest);
        Console.WriteLine(compoundInterest);

        ////////////////// Async Timer ////////////////////

        AsyncTimer timer1 = new AsyncTimer(Work1, 1000, 10);
        timer1.Start();

        AsyncTimer timer2 = new AsyncTimer(Work2, 500, 20);
        timer2.Start();

    }
Beispiel #44
0
    static void Main()
    {
        //with delegate:
        CalculateInterest calcSimpleInterst = GetSimpleInterest;
        CalculateInterest calcCompoundInterst = GetCompoundInterest;
        InterestCalculator firstExample = new InterestCalculator(500m, 5.6m, 10, calcCompoundInterst);
        InterestCalculator secondExample = new InterestCalculator(2500m, 7.2m, 15, calcSimpleInterst);

        Console.WriteLine(firstExample.EarnedInterest);
        Console.WriteLine(secondExample.EarnedInterest);

        //with Func<T1, T2, TResult>:
        Func<decimal, decimal, int, string> simpleInterest = GetSimpleInterest;
        Func<decimal, decimal, int, string> compundInterest = GetCompoundInterest;
        InterestCalculator thirdExample = new InterestCalculator(500m, 5.6m, 10, compundInterest);
        InterestCalculator fourthExample = new InterestCalculator(2500m, 7.2m, 15, simpleInterest);

        Console.WriteLine(thirdExample.EarnedInterest);
        Console.WriteLine(fourthExample.EarnedInterest);
    }
Beispiel #45
0
    static void Main()
    {
        // Chast ot resheniqta na problemite tuk sa vzeti ot foruma

        /* Solution for Problem 1/Interest Calculator/ */
        var interest = new InterestCalculator(500m, 5.6m, 10, GetCompoundInterest);
        Console.WriteLine(interest);
        var compoundInterest = new InterestCalculator(2500m, 7.2m, 15, GetSimpleInterest);
        Console.WriteLine(compoundInterest);

        /* Solution for Problem 2/Async Timer/ */
        AsyncTimer timer1 = new AsyncTimer(Work1, 1000, 10);
        timer1.Start();
        AsyncTimer timer2 = new AsyncTimer(Work2, 500, 20);
        timer2.Start();

        /* Solution for Problem 3/Student Class/ */
        var student = new Student("Go6o", 17);
        student.Name = "Zara";
        student.Age = 69;
    }
    static void Main()
    {
        Func<decimal, double, int, decimal> simpleInterest = (sum, interest, years) =>
        {
            decimal result = sum * (decimal)(1 + (interest / 100) * years);
            return result;
        };

        Func<decimal, double, int, decimal> compoundInterest = (sum, interest, years) =>
        {
            decimal result = sum * (decimal)((1 + (interest / 12 / 100)) * (years * 12));
            return result;
        };

        InterestCalculator calc = new InterestCalculator(500m, 5.6, 10, compoundInterest);
        Console.WriteLine(calc);

        InterestCalculator claclSimpleInterest = new InterestCalculator(2500m, 7.2, 15, simpleInterest);
        Console.WriteLine(claclSimpleInterest);

    }
 public Account(int theInterestRate, EventLog theEventLog)
 {
     _interestCalculator = new InterestCalculator(theInterestRate, theEventLog);
     _eventLog = theEventLog;
 }