Full Source Code

1:  using System;
2:  using System.IO; 
3:  using System.Linq;
4:  using System.Xml.Linq;
5:  using System.Threading;
6:  using System.Text;
7:  using System.Globalization;
8:  using System.Drawing;
9:  using MyLib; 
10:  namespace CalcNamespace 
11:  {
12:     public class CalcClass 
13:     {
14:        public static string CalcMethod (dynamic[] arrInput )
15:        {
16:           StringBuilder sbOutput= new StringBuilder(); //For output result
17:           Thread newSingleThread = new Thread(delegate()
18:           {
19:              try 
20:              {
21:              //-------------------------------------------------------             
22:              dynamic p=arrInput[0];
23:              dynamic i=arrInput[1];
24:              dynamic n=arrInput[2];
25:              dynamic a;
26:              dynamic total;
27:              dynamic inter;
28:              
29:              i=i/12.0/100.0;
30:              var k=(1-Math.Pow((1+i),-n) )/i;
31:              a=p/k;
32:              total=a*n;
33:              inter=total-p;
34:              
35:              
36:              a=a.ToString("f2");
37:              total=total.ToString("f2");
38:              inter=inter.ToString("f2");
39:              
40:              sbOutput.AppendLine("Your monthly payment will be:");
41:              sbOutput.AppendLine(a.ToString());sbOutput.AppendLine("Your total payment will be:");
42:              sbOutput.AppendLine(total.ToString());sbOutput.AppendLine("Your total interest payments will be");
43:              sbOutput.AppendLine(inter.ToString());
44:              //-------------------------------------------------------
45:               }
46:               catch(Exception ex)
47:               {
48:                  sbOutput.AppendLine("An error occurred! Would you please check your code or input parameters?");
49:                  sbOutput.AppendLine(ex.Message); 
50:               }
51:           }); //Thread End
52:  
53:           newSingleThread.Start();
54:           newSingleThread.Join(8000);
55:           return sbOutput.ToString();
56:  
57:        }//Method End
58:     } //Class End
59:  } //NameSpace End
60: