Click here to Skip to main content
15,884,628 members
Articles / Programming Languages / C# 3.5

Trading With World of Narnians

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
19 Jul 2013CPOL6 min read 23.6K   83   7  
Object oriented implementation of basic language processing / parsing leveraging LINQ / PRISM / UnityContainer.
using System;
using System.Collections.Generic;
using TradeWithNarnia.Symbol;
using System.Linq;

namespace TradeWithNarnia.Helper
{
  /// <summary>
  /// RomanSymbols to Arabic Numbers Converter 
  /// </summary>
  public class PriceConverter
  {
    public int GetArabicNumber(IEnumerable<RomanSymbol> romanSymbols)
    {
      if(RomanNumberValidator.IsRomanNumberValid(romanSymbols) == false)
      {
        throw new Exception("Invalid Roman Number");
      }

      int total = 0;
      if (romanSymbols.Any())
      {
        RomanSymbol[] romanSymbolArray = romanSymbols.ToArray();
        for (var i = 0; i < romanSymbolArray.Length; i++)
        {
          // last number just add the value and exit
          if (i + 1 == romanSymbolArray.Length)
          {
            total += (int) romanSymbolArray[i];
            break;
          }

          // exception found
          if (romanSymbolArray[i] < romanSymbolArray[i+1])
          {
            total += ((int) romanSymbolArray[i +1] - (int) romanSymbolArray[i]);
            i++;
          }
          else
          {
            total += (int) romanSymbolArray[i];
          }
        }
      }
      return total;
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Self Employed
India India
I am Gaurav Chhatbar. I have got a total IT experience of 10 years that involves developing, leading, managing and delivering IT solutions for business.

My core expertise lies around Dot Net as well as Java technologies. In the past, I have developed / owned applications, primarily for:
Front Office Trading – Equities, Fixed Income as well as Structured Products
Private Wealth Management – Trading and CRM

For most of my career, I have worked for Morgan Stanley, Mumbai, India.

Gaurav Chhatbar
chhatbar@gmail.com

Comments and Discussions