static void Main(string[] args) { Account deposit1 = new DepositAccount(new Individual(), 500m, 3.5m); Account deposit2 = new DepositAccount(new Company(), 1500m, 3.4m); Console.WriteLine(deposit1.CalculateInterestAmount(2)); // 0 Console.WriteLine(deposit2.CalculateInterestAmount(2)); // 6.8 Account loan1 = new LoanAccount(new Individual(), 1000m, 5m); Account loan2 = new LoanAccount(new Company(), 1000m, 5m); Console.WriteLine(loan1.CalculateInterestAmount(2)); // 0 Console.WriteLine(loan1.CalculateInterestAmount(4)); // 20 Console.WriteLine(loan2.CalculateInterestAmount(1)); // 0 Console.WriteLine(loan2.CalculateInterestAmount(3)); // 15 Account mortgage1 = new MortgageAccount(new Individual(), 1000m, 5m); Account mortgage2 = new MortgageAccount(new Company(), 1000m, 5m); Console.WriteLine(mortgage2.CalculateInterestAmount(11)); // 65 / 2 = 27.5 Console.WriteLine(mortgage2.CalculateInterestAmount(13)); // 65 Console.WriteLine(mortgage1.CalculateInterestAmount(5)); // 0 Console.WriteLine(mortgage1.CalculateInterestAmount(7)); // 35 Individual customer1 = new Individual("Pesho"); Company customer2 = new Company("Telerik"); Console.WriteLine(customer1.Name); // Pesho Console.WriteLine(customer2.Name); // Telerik }
/*2. A bank holds different types of accounts for its customers: * deposit accounts, loan accounts and mortgage accounts. Customers could be individuals or companies.*/ /*All accounts have customer, balance and interest rate (monthly based). * Deposit accounts are allowed to deposit and with draw money. * Loan and mortgage accounts can only deposit money.*/ /*All accounts can calculate their interest amount for a given period (in months). * In the common case its is calculated as follows: number_of_months * interest_rate.*/ /*Loan accounts have no interest for the first 3 months * if are held by individuals and for the first 2 months if are held by a company.*/ /* Deposit accounts have no interest if their balance is positive and less than 1000. */ /* Mortgage accounts have ½ interest for the first 12 months for companies and no interest for the first 6 months for individuals.*/ static void Main() { //create customers Person person = new Person("Tervel", "Kubratov", "Sofia"); Person someone = new Person("King", "Arthur", "Dublin"); Company company = new Company("Tervel OOD", "Sofia", TypeOfFirm.LTD); //create aacounts, interest 3% = 0.03M DepositAccount depositPerson = new DepositAccount(person, 450.00M, 0.03M, 4); depositPerson.Balance = depositPerson.DepositeMoney(2400M); Console.WriteLine("Balance of {0} is {1:C3}", person.FirstName, depositPerson.Balance); Console.WriteLine("Interest Amount of deposit {0} is {1}", person.FirstName, depositPerson.CalculateInterestAmount()); LoanAccount loanPerson = new LoanAccount(person, 3200.0M, 0.04M, 13); Console.WriteLine("Interest Amount of loan {0} is {1}", person.FirstName, loanPerson.CalculateInterestAmount()); MortgageAccount mortgagePerson = new MortgageAccount(person, 5060.80M, 0.05M, 14); Console.WriteLine("Interest Amount of mortgage {0} is {1}", person.FirstName, mortgagePerson.CalculateInterestAmount()); Console.WriteLine(); DepositAccount depositSomeone = new DepositAccount(someone, 3000.50M, 0.023M, 2); Console.WriteLine("Balance of {0} is {1:C3}", someone.FirstName, depositSomeone.Balance); Console.WriteLine(); DepositAccount depositSome = new DepositAccount(company, 500.0M, 0.07M, 5); Console.WriteLine("Balance of \"{0}\" is {1:C3}", company.CompanyName, depositSome.Balance); Console.WriteLine("Interest Amount of deposit {0} is {1}", company.CompanyName, depositSome.CalculateInterestAmount()); MortgageAccount mortgageCompany = new MortgageAccount(company, 2500.00M, 0.05M, 13); Console.WriteLine("Interest Amount of mortgage {0} is {1}", company.CompanyName, mortgageCompany.CalculateInterestAmount()); }
static void Main() { Individual ivo = new Individual("Ivo", "Dimov", "Sofia"); Company compy = new Company("Tech OOD", "Sofia"); var firstMorg = new MortgageAccount(ivo, 200, 4); var secMorg = new MortgageAccount(compy, 300, 4); Console.WriteLine(firstMorg.CalculateInterestAmount(4)); // 0 Console.WriteLine(secMorg.CalculateInterestAmount(4)); // 16/2 = 8 var firstLoan = new LoanAccount(ivo, 200, 4); var secLoan = new LoanAccount(compy, 300, 4); Console.WriteLine(firstLoan.CalculateInterestAmount(4)); // 1 month * 4 = 4 Console.WriteLine(secLoan.CalculateInterestAmount(4)); // 2 months * 4 = 8 }