示例#1
0
        static void HomePayment()                                                                   // method containing if statment that will determin via user input whether or not they will be renting , buying or not paying rent etc.
        {
            Console.WriteLine("Please type 1 if renting a home or 2 if you are paying off a home loan. ");

            Console.WriteLine("If neither press 3 else press anything else to exit");

            var answer = Console.ReadLine();

            if (answer.Equals("1"))                                                                 // if statement for determining living status costs
            {
                Console.WriteLine("Please enter how much is spent on rent per month: ");

                Rent amount = new Rent();

                amount.PrintLine();

                amount.Amount();
            }
            else if (answer.Equals("2"))
            {
                var amount = new HomeLoan();

                amount.Amount();
            }

            else if (answer.Equals("3"))                                // if user chooses 3 the program continues with R0 paid for living expenses
            {
                Expense.Expenses.Add(0);                                // Rent free in your head- Cranberries zombie
            }
            else
            {
                Environment.Exit(0);
            }
        }
示例#2
0
        public bool validate(HomeLoan home)
        {
            if (BusinessLogicUtil.validate(home.CustomerID) == false)
            {
                throw new InvalidStringException("Invalid Customer ID");
            }

            if (home.AmountApplied >= 2000001)
            {
                throw new InvalidAmountException("Maximum loan amount is Rs.20 lakh");
            }

            if (home.RepaymentPeriod >= 16)
            {
                throw new InvalidRangeException("Repayment period can be maximum of 15 years");
            }

            if (home.SalaryDeductions >= home.GrossIncome)
            {
                throw new InvalidAmountException("Salary deduction can't be greater than or equal to Gross salary");
            }

            if (home.ServiceYears < 5)
            {
                throw new InvalidRangeException("Service experience must be minimum of 5 years");
            }

            return(true);
        }
示例#3
0
        public bool ApplyLoanDAL(HomeLoan home)
        {
            //List<HomeLoan> loanList = new List<HomeLoan>();
            var loanList = DeserializeFromJSON("HomeLoans.txt");

            loanList.Add(home);
            return(SerializeIntoJSON(loanList, "HomeLoans.txt"));
        }
示例#4
0
        public void OutstandingDebtInTerm0ShouldBeTheSameAsAmmountToBorrow(double outstandingDebt)
        {
            var loanCalc = new SeriesLoanCalculator();
            var loan     = new HomeLoan(loanCalc);
            var a        = loan.CalculatePaymentPlan(outstandingDebt, 10);

            Assert.IsTrue(a.First(x => x.Term == 0).OutstandingDebt == outstandingDebt);
        }
示例#5
0
        public void TheUserShouldNeverPayMoreThanTheyOwe()
        {
            var loanCalc = new SeriesLoanCalculator();
            var loan     = new HomeLoan(loanCalc);
            var a        = loan.CalculatePaymentPlan(1000000, 30);

            Assert.IsTrue(!a.Any(x => x.OutstandingDebt < 0));
        }
示例#6
0
        public void IsValid_WhenLoanIsValid_ReturnsNoBrokenBusinessRule()
        {
            // Arrange
            var loan = new HomeLoan(1000, 1, 2.5m, CurrencyType.Euro);

            // Act
            var response    = loan.IsValidLoan();
            var brokenRules = loan.GetBrokenBusinessRulesOnThisLoan();

            // Assert
            Assert.IsTrue(response, "Expected loan state to be valid.");
            Assert.AreEqual(0, brokenRules.Count, "Expected no business rule to be violated.");
        }
示例#7
0
        public void GetRepaymentsFor_WhenPrincipalIs100kAndTermIs30YearsAndInterestIs6Percent_MonthlyRepaymentsAre599_55()
        {
            // Arrange
            const decimal expectedMonthlyPayment = 599.55m;

            var loan = new HomeLoan(100000, 30, 6, CurrencyType.Euro);

            // Act
            var actualMonthlyPayment = Decimal.Round(loan.GetRepaymentAmount(), 2);

            // Assert
            Assert.AreEqual(expectedMonthlyPayment, actualMonthlyPayment);
        }
示例#8
0
        public void TotalAmmountInInterests()
        {
            var    loanCalc  = new SeriesLoanCalculator();
            var    loan      = new HomeLoan(loanCalc);
            var    a         = loan.CalculatePaymentPlan(1000000, 20);
            double interests = 0.0;

            foreach (var payment in a)
            {
                interests += payment.Interest;
            }
            Assert.IsTrue(Math.Round(interests, 0) == 351458);
        }
示例#9
0
        public void GetRepaymentsFor_WhenPrincipalIs1000AndTermIs30YearsAndInterestIsZeroPercent_MonthlyRepaymentsAre_100()
        {
            // Arrange
            const decimal expectedMonthlyPayment = 100m;

            var loan = new HomeLoan(2400, 2, 0, CurrencyType.Euro);

            // Act
            var actualMonthlyPayment = loan.GetRepaymentAmount();

            // Assert
            Assert.AreEqual(expectedMonthlyPayment, actualMonthlyPayment);
        }
示例#10
0
        public void IsValid_WhenTermIsLessThan1Year_ReturnsBrokenBusinessRule()
        {
            // Arrange
            var loan = new HomeLoan(1000, 0, 2.5m, CurrencyType.Euro);

            // Act
            var response    = loan.IsValidLoan();
            var brokenRules = loan.GetBrokenBusinessRulesOnThisLoan();

            // Assert
            Assert.IsFalse(response, "Expected loan state to be invalid.");
            Assert.AreEqual(1, brokenRules.Count, "Expected a single business rule to be violated.");
            Assert.AreEqual(ValidationMessages.InvalidHomeLoanTerm, brokenRules[0].Description);
        }
示例#11
0
 public void OnPost()
 {
     if (ModelState.IsValid)
     {
         try
         {
             HomeLoan homeLoan = new HomeLoan(_seriesLoanCalculator);
             Payments = homeLoan.CalculatePaymentPlan(Amount, NumberOfYears);
         }
         catch (Exception e)
         {
             //writing error to log, otherwise ignoring them, the end user gets a message through model validation
             _logger.LogWarning("Something went wrong", e);
         }
     }
 }
示例#12
0
        public bool ApplyLoanBL(HomeLoan home)
        {
            //HomeLoan home = (HomeLoan)(Object)obj;
            if (validate(home) == true)
            {
                home.LoanID            = "HOME" + BusinessLogicUtil.SystemDateToString();
                home.InterestRate      = 8.50;
                home.EMI_Amount        = BusinessLogicUtil.ComputeEMI(home.AmountApplied, home.RepaymentPeriod, home.InterestRate);
                home.DateOfApplication = DateTime.Now;
                home.Status            = (LoanStatus)0; // APPLIED

                HomeLoanDAL homeDAL = new HomeLoanDAL();
                return(homeDAL.ApplyLoanDAL(home));
            }
            return(false);
        }
示例#13
0
        public HomeLoan ApproveLoanDAL(string loanID, LoanStatus updatedStatus)
        {
            List <HomeLoan> homeLoans   = DeserializeFromJSON("HomeLoans.txt");
            HomeLoan        objToReturn = new HomeLoan();

            foreach (HomeLoan Loan in homeLoans)
            {
                if (Loan.LoanID == loanID)
                {
                    Loan.Status = updatedStatus;
                    objToReturn = Loan;
                    break;
                }
            }

            SerializeIntoJSON(homeLoans, "HomeLoans.txt");
            return(objToReturn);
        }
示例#14
0
        public void HomeLoanConstructor_WhenInitializedByConstructor_PropertiesAreSetCorrectly()
        {
            // Arrange
            decimal      loanAmount       = 1000;
            decimal      loanInterestRate = 3.5m;
            int          loanTerm         = 5;
            CurrencyType loanCurrency     = CurrencyType.UsDollars;


            // Act
            var loan = new HomeLoan(loanAmount, loanTerm, loanInterestRate, loanCurrency);

            // Assert
            Assert.AreEqual(loanAmount, loan.Principal, "Loan amount not set correctly by constructor");
            Assert.AreEqual(loanTerm, loan.Term, "Loan term not set correctly by constructor");
            Assert.AreEqual(loanInterestRate, loan.InterestRatePercentage, "Loan interest rate not set correctly by constructor");
            Assert.AreEqual(loanCurrency, loan.Currency, "Loan currency type not set correctly by constructor");
        }
示例#15
0
        public static Loan CreateLoanInstance(LoanType type, double interestRate)
        {
            Loan loanObject = default(Loan);

            switch (type)
            {
            case LoanType.Business:
                loanObject = new BusinessLoan(interestRate);
                break;

            case LoanType.Education:
                loanObject = new EducationLoan(interestRate);
                break;

            case LoanType.Home:
                loanObject = new HomeLoan(interestRate);
                break;
            }

            return(loanObject);
        }
示例#16
0
        public HomeLoanResponse NewHomeLoan(HomeLoanServiceRequest request)
        {
            var response = new HomeLoanResponse();

            var newLoan = new HomeLoan(request.Amount, request.Term, request.InterestRate, request.Currency);

            if (newLoan.IsValidLoan())
            {
                response.Loan                 = newLoan;
                response.PaymentPlan          = newLoan.GetRepaymentSchedule(request.FirstRepaymentDate).ToList();
                response.TotalRepaymentAmount = (Decimal.Round(newLoan.GetRepaymentAmount(), 2) * request.Term * 12);
                response.Status               = ServiceStatus.Success;
            }
            else
            {
                response.Status = ServiceStatus.Failure;
                response.BrokenBusinessRules = newLoan.GetBrokenBusinessRulesOnThisLoan();
            }

            return(response);
        }
示例#17
0
        public ILoan Create(LoanType loanType)
        {
            ILoan loan = null;

            switch (loanType)
            {
            case LoanType.HomeLoan:
                loan = new HomeLoan();
                break;

            case LoanType.CarLoan:
                loan = new CarLoan();
                break;

            case LoanType.PersonalLoan:
                loan = new PersonalLoan();
                break;

            default:
                break;
            }
            return(loan);
        }
示例#18
0
        private static void TemplatePattern()
        {
            AutoLoan     autoLoan     = new AutoLoan();
            HomeLoan     homeLoan     = new HomeLoan();
            PersonalLoan personalLoan = new PersonalLoan();

            autoLoan.ProcessLoan();
            homeLoan.ProcessLoan();
            personalLoan.ProcessLoan();

            //Template.CarTemplate audi = new Template.Audi();
            //Template.CarTemplate bmw = new Template.BMW();
            //Template.CarTemplate benz = new Template.Benz();

            //audi.BuildCare();
            //bmw.BuildCare();
            //benz.BuildCare();

            //HouseTemplate woodenHouse = new WoodenHouse();
            //woodenHouse.BuildHouse();

            //HouseTemplate glassHouse = new GlassHouse();
            //glassHouse.BuildHouse();
        }