Advertisement
NPSF3000

Bonds Paying Bonds Interest :)

Jun 22nd, 2011
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace NBNFunding
  7. {
  8.     class Program
  9.     {
  10.  
  11.         struct Bond
  12.         {
  13.             private decimal value;
  14.             public decimal Value
  15.             {
  16.                 get
  17.                 {
  18.                     return value;
  19.                 }
  20.             }
  21.  
  22.             private int created;
  23.  
  24.             public int Created
  25.             {
  26.                 get
  27.                 {
  28.                     return created;
  29.                 }
  30.             }
  31.  
  32.             public Bond(decimal value)
  33.             {
  34.                 this.value = value;
  35.                 this.created = year;
  36.  
  37.             }
  38.  
  39.         }
  40.  
  41.         static List<Bond> Bonds = new List<Bond>();
  42.         static int year = 2011;
  43.  
  44.         static void Main(string[] args)
  45.         {
  46.             //Time to Run Simulation
  47.             int TimeFrame = 10 + year;
  48.  
  49.             //Initial Debt;
  50.             Bonds.Add(new Bond(1000));
  51.  
  52.  
  53.             for (; year <= TimeFrame; year++)
  54.             {
  55.                 Console.WriteLine("Year: " + year);
  56.  
  57.                 Console.WriteLine("Total Debt: ");
  58.  
  59.                 Console.WriteLine(TotalDebt().ToString("C"));
  60.  
  61.                 decimal interestOwed = TotalDebt() * 0.05m;
  62.  
  63.                 Console.WriteLine("Interest: ");
  64.  
  65.                 Console.WriteLine(interestOwed.ToString("C"));
  66.  
  67.                 PayInterest(interestOwed);
  68.  
  69.                 Console.WriteLine("");
  70.             }
  71.            
  72.             Console.WriteLine();
  73.  
  74.             Console.WriteLine("After " + TimeFrame + " years, the following bonds have accured:");
  75.  
  76.             Console.WriteLine();
  77.  
  78.             Bonds.ForEach(bond =>
  79.             {
  80.                 Console.WriteLine("Bond Value: "+bond.Value.ToString("C"));
  81.                 Console.WriteLine("Bond Created: " + bond.Created);
  82.                 Console.WriteLine();
  83.             });
  84.  
  85.             Console.WriteLine();
  86.  
  87.             Console.WriteLine("Total Bonds: " + Bonds.Count());
  88.             Console.WriteLine("Total Bond Value: " + TotalDebt().ToString("C"));
  89.             Console.ReadKey();
  90.         }
  91.  
  92.         static decimal TotalDebt()
  93.         {
  94.             decimal result = 0;
  95.  
  96.             Bonds.ForEach(bond => result += bond.Value);
  97.  
  98.             return result;
  99.         }
  100.  
  101.  
  102.         static void PayInterest(decimal interest)
  103.         {
  104.             Bonds.Add(new Bond(interest));
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement