Esempio n. 1
0
 static void DisplayLoanInformation(PaymentCalculator calculator)
 {
     Console.WriteLine("Purchase Price: {0:C}", calculator.PurchasePrice);
     Console.WriteLine("Down Payment: {0:C}", calculator.DownPayment);
     Console.WriteLine("Loan Amount: {0:C}", calculator.LoanAmount);
     Console.WriteLine("Annual Interest Rate: {0}%", calculator.InterestRate);
     Console.WriteLine("Term: {0} years ({1} months)", calculator.LoanTermYears, calculator.LoanTermMonths);
     Console.WriteLine("Monthly Payment: {0:C}", calculator.CalculatePayment());
     Console.WriteLine();
 }
Esempio n. 2
0
        private void Initialize()
        {
            Name  = Name ?? "Default Name";
            Years = Math.Max(1, Years);

            HomePurchaseAmount = Math.Max(1m, HomePurchaseAmount).ToDollars();

            OwnerDownPaymentPercentage = Math.Min(Math.Max(0m, OwnerDownPaymentPercentage), 100).ToPercent();
            OwnerDownPayment           = (HomePurchaseAmount * OwnerDownPaymentPercentage).ToDollars();
            OwnerInterestRatePerYear   = Math.Min(Math.Max(0m, OwnerInterestRatePerYear), 100).ToPercent();
            OwnerLoanAmount            = HomePurchaseAmount - OwnerDownPayment;
            OwnerLoanYears             = Math.Max(1, OwnerLoanYears);
            OwnerMonthlyPayment        = PaymentCalculator.CalculatePayment(OwnerLoanAmount, OwnerInterestRatePerYear, OwnerLoanYears);

            LandlordDownPaymentPercentage           = LandlordDownPaymentPercentage ?? OwnerDownPaymentPercentage;
            LandlordDownPaymentPercentage           = Math.Min(Math.Max(0m, LandlordDownPaymentPercentage.Value), 100).ToPercent();
            LandlordDownPayment                     = (HomePurchaseAmount * LandlordDownPaymentPercentage.Value).ToDollars();
            LandlordInterestRatePerYear             = LandlordInterestRatePerYear ?? OwnerInterestRatePerYear;
            LandlordInterestRatePerYear             = Math.Min(Math.Max(0m, LandlordInterestRatePerYear.Value), 100).ToPercent();
            LandlordManagementFeePercentagePerMonth = Math.Min(Math.Max(0m, LandlordManagementFeePercentagePerMonth), 100).ToPercent();
            LandlordVacancyFeePercentage            = Math.Min(Math.Max(0m, LandlordVacancyFeePercentage), 100).ToPercent();
            LandlordLoanAmount     = HomePurchaseAmount - LandlordDownPayment;
            LandlordLoanYears      = Math.Max(1, LandlordLoanYears ?? OwnerLoanYears);
            LandlordMonthlyPayment = PaymentCalculator.CalculatePayment(LandlordLoanAmount, LandlordInterestRatePerYear.Value, LandlordLoanYears.Value);

            DiscountRatePerYear     = Math.Min(Math.Max(0m, DiscountRatePerYear), 100).ToPercent();
            CapitalGainsRatePerYear = Math.Min(Math.Max(0m, CapitalGainsRatePerYear), 100).ToPercent();
            MarginalTaxRatePerYear  = Math.Min(Math.Max(0m, MarginalTaxRatePerYear), 100).ToPercent();
            InflationRatePerYear    = Math.Min(Math.Max(0m, InflationRatePerYear), 100).ToPercent();

            BuyerFixedCosts = Math.Max(0m, BuyerFixedCosts).ToDollars();
            BuyerVariableCostsPercentage = Math.Min(Math.Max(0m, BuyerVariableCostsPercentage), 100).ToPercent();
            PropertyTaxPercentagePerYear = Math.Min(Math.Max(0m, PropertyTaxPercentagePerYear), 100).ToPercent();
            InsurancePerMonth            = Math.Max(0m, InsurancePerMonth).ToDollarCents();
            HoaPerMonth = Math.Max(0m, HoaPerMonth).ToDollarCents();
            HomeAppreciationPercentagePerYear = Math.Min(Math.Max(0m, HomeAppreciationPercentagePerYear ?? InflationRatePerYear), 100).ToPercent();
            HomeMaintenancePercentagePerYear  = Math.Min(Math.Max(0m, HomeMaintenancePercentagePerYear), 100).ToPercent();
            SellerCommissionPercentage        = Math.Min(Math.Max(0m, SellerCommissionPercentage), 100).ToPercent();
            SellerFixedCosts      = Math.Max(0m, SellerFixedCosts).ToDollars();
            DepreciationYears     = Math.Max(1, DepreciationYears).ToValue();
            DepreciablePercentage = Math.Min(Math.Max(0m, DepreciablePercentage), 100).ToPercent();

            RentChangePerYearPercentage = Math.Min(Math.Max(0m, RentChangePerYearPercentage ?? HomeAppreciationPercentagePerYear ?? InflationRatePerYear), 100).ToPercent();
            var defaultRent =
                OwnerMonthlyPayment +
                InsurancePerMonth +
                HoaPerMonth +
                HomePurchaseAmount * PropertyTaxPercentagePerYear / 12 +
                HomePurchaseAmount * HomeMaintenancePercentagePerYear / 12;

            RentPerMonth              = Math.Max(1m, RentPerMonth ?? defaultRent).ToDollars();
            RentersInsurancePerMonth  = Math.Max(0m, RentersInsurancePerMonth).ToDollarCents();
            RentSecurityDepositMonths = Math.Max(0, RentSecurityDepositMonths);
        }
        public decimal LoanPayment(decimal purchaseprice, decimal interestRate, double loanyears)
        {
            var pCalculator = new PaymentCalculator
            {
                PurchasePrice = purchaseprice,
                InterestRate  = interestRate,
                LoanTermYears = loanyears
            };

            return(pCalculator.CalculatePayment());
        }
        public void PaymentCalculatorTest()
        {
            const decimal compareamount = (decimal)966.64;
            var           paymentcalc   = new PaymentCalculator();

            paymentcalc.PurchasePrice = 50000;
            paymentcalc.InterestRate  = (decimal)6.0;
            paymentcalc.LoanTermYears = 5;

            var acutalCalculatePayment = paymentcalc.CalculatePayment();

            Assert.AreEqual(acutalCalculatePayment, compareamount);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            _mortgagesDAL = new MortgagesDAL();

            var mortgage = new Mortgage();
            var address  = new Address();

            Console.WriteLine("Calculate your new mortgage!");
            Console.WriteLine();

            Console.WriteLine("Please create or enter your User Name?");
            mortgage.UserName = Console.ReadLine();
            Console.WriteLine();

            Console.WriteLine("What is your purchase price?");
            mortgage.PurchasePrice = double.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("What is your down payment?");
            mortgage.DownPayment = double.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("What is the interest rate?");
            mortgage.InterestRate = double.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("How long will your loan be? 15 years or 30 years?");
            mortgage.TermLength = double.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("What are your yearly taxes?");
            mortgage.Taxes = double.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("How much is your Homeowner's Insurance per year?");
            mortgage.Insurance = double.Parse(Console.ReadLine());
            Console.WriteLine();

            //calculate payment with taxes and insurance
            PaymentCalculator calculatePayment = new PaymentCalculator();

            double printPayment = calculatePayment.CalculatePayment(mortgage.PurchasePrice, mortgage.DownPayment, mortgage.InterestRate, mortgage.TermLength, mortgage.Taxes, mortgage.Insurance);

            // Displays Mortgage Payment
            Console.WriteLine($"Your new mortgage, including taxes and insurance is ${printPayment}. ");

            Console.WriteLine("Would you like to SAVE this mortgage to an address, Y or N?");
            string input = Console.ReadLine();

            if (input == "N")
            {
                Console.WriteLine("Would you like to try another query, Y or N?");
                string input2 = Console.ReadLine();
                if (input2 == "N")
                {
                    Console.WriteLine("Thank you and goodbye!");
                }
                else
                {
                    Console.WriteLine("Press ENTER to start over");
                }
            }
            else
            {
                _mortgagesDAL.SubmitMortgage(mortgage);
                Console.WriteLine("What is the property street address?");
                address.Street = Console.ReadLine();
                Console.WriteLine();
                Console.WriteLine("What city is the property located in?");
                address.City = Console.ReadLine();
                _mortgagesDAL.SubmitAddress(address);
            }
        }