Exemple #1
0
        /// <summary>
        /// Entry point for program.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            LoanContext context = null;
            LoanCalculator calculator = null;
            LoanCalculationOutput output = null;
            LoanCalculationOutputStreamWriter writer = null;
            try
            {
                // clean the program name
                programName = programName.Replace(".exe",  string.Empty);
                // check we have the required number of arguments
                if(args.Length != EXPECTED_ARGUMENT_COUNT)
                {
                    PrintUsage();
                    return;
                }
                string outputFilename = BuildOutputFilename();
                context = new LoanContext();
                ProcessArguments(args, context);
                context.TodaysDate = DateTime.Now;
                calculator = new LoanCalculator(context);
                output = calculator.Calculate();
                writer = new LoanCalculationOutputStreamWriter(context, output);

                using(StreamWriter fs = new StreamWriter(new FileStream(outputFilename, FileMode.Create)))
                {
                    writer.WriteOutputHeader(fs, programName);
                    writer.WritetCalculations(fs);
                }

                writer.WriteOutputHeader(System.Console.Out, programName);
                writer.WritetCalculations(System.Console.Out);
                System.Console.WriteLine(string.Format("Ouput written to file '{0}'.", outputFilename));
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(string.Format("Exception occurred: {0}", ex.Message));
                System.Console.WriteLine(string.Format("\n\n{0}", ex.StackTrace));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LoanCalculationOutputStreamWriter"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="output">The output.</param>
 public LoanCalculationOutputStreamWriter(LoanContext context, LoanCalculationOutput output)
 {
     this.context = context;
     this.output = output;
 }
Exemple #3
0
 /// <summary>
 /// Processes the arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <param name="context">The context.</param>
 private static void ProcessArguments(string[] args, LoanContext context)
 {
     context.StartDate = DateTime.ParseExact(args[0], Constants.DATE_FORMAT, CultureInfo.InvariantCulture);
     context.TargetEndDate = DateTime.ParseExact(args[1], Constants.DATE_FORMAT, CultureInfo.InvariantCulture);
     context.Balance = double.Parse(args[2]);
     context.InterestRate = double.Parse(args[3]);
     context.MinRepaymentAmount = double.Parse(args[4]);
     context.MinRepaymentDay = int.Parse(args[5]);
     context.ExtraRepaymentAmount = double.Parse(args[6]);
     context.ExtraRepaymentDay = int.Parse(args[7]);
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoanCalculator"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public LoanCalculator(LoanContext context)
 {
     this.context = context;
 }