Ejemplo n.º 1
0
 // default constructor
 public ClientPortfolio()
 {
     StockList     = new StockList();
     HolderName    = null;
     HolderAddress = null;
     ContactNumber = null;
 }
Ejemplo n.º 2
0
        //param   (StockList)listToMerge : second list to be merged
        //summary      : merge two different list into a single result list
        //return       : merged list
        //return type  : StockList
        public StockList MergeList(StockList listToMerge)
        {
            StockList resultList = new StockList();
            StockNode node       = head;

            while (node != null)
            {
                resultList.AddStock(node.StockHolding);
                node = node.Next;
            }


            StockNode mergeNode = listToMerge.head;

            //Adding the stock value to the list
            while (mergeNode != null)
            {
                resultList.AddStock(mergeNode.StockHolding);
                mergeNode = mergeNode.Next;
            }



            return(resultList);
        }
Ejemplo n.º 3
0
 // Construtor for initialization
 public ClientPortfolio(string holderName, string holderAddress, string contactNumber)
 {
     StockList      = new StockList();
     PortfolioValue = 0.0m;
     HolderName     = holderName;
     HolderAddress  = holderAddress;
     ContactNumber  = contactNumber;
 }
Ejemplo n.º 4
0
        //param  (StockList) listToCompare     : StockList which has to comared for similarity index
        //summary      : finds the similar number of nodes between two lists
        //return       : similarty index
        //return type  : int
        public int Similarity(StockList listToCompare)
        {
            int similarityIndex = 0;

            // write your implementation here

            // Similarity

            StockNode stocknode  = this.head;
            StockNode stocknode2 = listToCompare.head;

            while (stocknode != null)
            {
                while (stocknode2 != null)
                {
                    if (stocknode.StockHolding.Symbol == stocknode2.StockHolding.Symbol)
                    {
                        if (stocknode.Next == null || stocknode2.Next == null)
                        {
                            similarityIndex = similarityIndex + 1;
                        }
                        else if (stocknode.StockHolding.Symbol == stocknode.Next.StockHolding.Symbol || stocknode2.StockHolding.Symbol == stocknode2.Next.StockHolding.Symbol)
                        {
                            similarityIndex = similarityIndex + 0;
                        }
                        else
                        {
                            similarityIndex = similarityIndex + 1;
                        }
                    }
                    stocknode2 = stocknode2.Next;
                }
                stocknode2 = listToCompare.head;
                stocknode  = stocknode.Next;
            }

            return(similarityIndex);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Stock stockOne   = new Stock("GOOG", "Google", 1.2m, 6.27m);
            Stock stockTwo   = new Stock("MSFT", "Microsoft", 5m, 111.2m);
            Stock stockThree = new Stock("AAPL", "Apple", 6m, 222.7m);
            Stock stockFour  = new Stock("AMZN", "Amazon", 1.2m, 198.7m);
            Stock stockFive  = new Stock("Z", "Zillow", 2.4m, 207.6m);
            Stock stockSix   = new Stock("B", "Barnes ", 2.2m, 68.7m);
            Stock stockSeven = new Stock("GOOG", "Google", 3.6m, 115.3m);
            Stock stockEight = new Stock("AAPL", "Apple", 5m, 147.6m);
            Stock stockNine  = new Stock("GOOG", "Google", 1.2m, 6.27m);

            ClientPortfolio client1 = new ClientPortfolio("Andrew", "Mountain View", "555-111-9070");

            client1.StockList.AddStock(stockOne);
            client1.StockList.AddStock(stockTwo);
            client1.StockList.AddStock(stockThree);
            client1.StockList.AddStock(stockFour);
            client1.StockList.AddStock(stockNine);

            ////Console.WriteLine("**************************Client-1 Portfolio*****************************************");
            //Console.WriteLine("********************CLIENT 1 (ONE)*****************************");
            client1.StockList.Print();
            Console.WriteLine("Number of shares :" + client1.StockList.Length());
            Console.WriteLine("Current value of protfolio for client 1 :" + client1.GetPortfolioValue());
            Console.WriteLine("Stock with most shares for client 1:" + client1.StockList.MostShares());
            client1.StockList.Sort_Version2();
            Console.WriteLine("Portfolio sorted in descending order by number of holdings for client 1:");
            client1.StockList.Print();
            client1.StockList.sortByName();
            Console.WriteLine("Portfolio sorted in alphabatical order for client 1:");
            client1.StockList.Print();
            Console.WriteLine();


            //Console.WriteLine("**************************Client-2 Portfolio*****************************************");
            //Console.WriteLine("********************CLIENT 2 (TWO)*****************************");
            ClientPortfolio client2 = new ClientPortfolio("Chris", "New York", "435-111-000");

            client2.StockList.AddStock(stockFive);
            client2.StockList.AddStock(stockSix);
            client2.StockList.AddStock(stockSeven);
            client2.StockList.AddStock(stockEight);

            client2.StockList.Print();
            Console.WriteLine("Number of shares :" + client2.StockList.Length());
            Console.WriteLine("Current value of protfolio for client 2 :" + client2.GetPortfolioValue());
            Console.WriteLine("Stock with most shares for client 2 :" + client2.StockList.MostShares());
            client2.StockList.Sort_Version2();
            Console.WriteLine("Portfolio sorted in descending order by number of holdings for client 2:");
            client2.StockList.Print();
            client2.StockList.sortByName();
            Console.WriteLine("Portfolio sorted in alphabatical order for client 2:");
            client2.StockList.Print();
            Console.WriteLine();

            Console.WriteLine("Similarity Index for Client-1 and Clien-2 :" + client1.StockList.Similarity(client2.StockList));

            Console.WriteLine("**************************Client-1,Client -2 Merged Portfolio*****************************************");
            StockList mergedPortfolio = client1.StockList.MergeList(client2.StockList);

            mergedPortfolio.Print();

            Console.ReadLine();
        }