Example #1
0
        /// <summary>
        /// Calculates minimum payment based off total, APR, and months inputted.
        /// Returns calculated decimal)paymentAmount
        /// </summary>
        /// <param name="loan">Single Loan</param>
        /// <returns></returns>
        public static decimal calculateMinimumPayment(LoanModel loan)
        {
            // TODO -- REWORK CALCULATIONS
            decimal total         = loan.LoanAmount;
            decimal interest      = (decimal)(loan.Apr / 100);
            decimal paymentAmount = 0;
            int     months        = loan.Months;

            paymentAmount = total * (1 + interest) / months;

            return(paymentAmount);
        }
Example #2
0
        /// <summary>
        /// Calculates number of months need to pay off loan. Uses object values and returns (int)months
        /// </summary>
        /// <param name="loan">Single Loan</param>
        /// <returns></returns>
        public static int calculateMonths(LoanModel loan)
        {
            // TODO -- REWORK CALCULATIONS
            decimal total         = loan.LoanAmount;
            decimal interest      = (decimal)(1 + loan.Apr);
            decimal paymentAmount = loan.MinimumPayment;
            int     months        = 1;

            while (total > 0)
            {
                total  = total * interest;
                total -= paymentAmount;
                ++months;
            }

            return(months);
        }
Example #3
0
        // TODO -- Create function that references this file from index.csv
        public static void OpenFromCsv(PeopleModel profile)
        {
            List <string> lines = new List <string>();

            // Read lines from file
            try {
                lines = File.ReadAllLines(profile.FileName).ToList();
            }
            catch {
                MessageBox.Show("Unable to open file");
                return;
            }

            // Parse through each line and add to loan list
            if (lines.Count() > 1 && lines[1] != "")
            {
                foreach (var line in lines.Skip(1))
                {
                    string[] entries = line.Split(',');

                    int     id;
                    decimal total;
                    decimal apr;
                    int     term;

                    Int32.TryParse(entries[0], out id);
                    Decimal.TryParse(entries[1], out total);
                    Decimal.TryParse(entries[2], out apr);
                    Int32.TryParse(entries[3], out term);

                    LoanModel tempLoan = new LoanModel(id, total, apr, term);

                    profile.AddToLoanList(tempLoan);
                }
            }


            lines = null;
        }
Example #4
0
 public void AddToLoanList(LoanModel loan)
 {
     Loans.Add(loan);
     LoanAddedEvent?.Invoke(this, "Loan Added"); // use to update loanListBox in LoanListViewer
 }