Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        Kangaroo kangaroo = new Kangaroo();

        kangaroo.Run();

        CamelCase camelCase = new CamelCase();

        camelCase.Run();

        StrongPassword strongPassword = new StrongPassword();

        strongPassword.Run();

        GradingStudents gradingStudents = new GradingStudents();

        gradingStudents.Run();

        IceCreamParlor iceCreamParlor = new IceCreamParlor();

        iceCreamParlor.Run();

        SockMerchant sockMerchant = new SockMerchant();

        sockMerchant.Run();

        RepeatedStrings repeatedStrings = new RepeatedStrings();

        repeatedStrings.Run();
    }
Ejemplo n.º 2
0
        // I.method
        public Animal createAnimal(int animalCode)
        {
            Animal newAnimal = null;

            switch (animalCode)
            {
            case 0:
                newAnimal = new Kangaroo();
                break;

            case 1:
                newAnimal = new Dingo();
                break;

            case 2:
                newAnimal = new Crocodile();
                break;

            case 3:
                newAnimal = new Koala();
                break;
            }

            return(newAnimal);
        }
Ejemplo n.º 3
0
        public void CanMeetAtOnePoint_ShouldReturnIfKangasHaveMet(int x1, int v1, int x2, int v2, string expected)
        {
            //Arrange

            //Act
            string actual = Kangaroo.CanMeetAtOnePoint(x1, v1, x2, v2);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void TestCase0()
        {
            int    x1       = 0;
            int    x2       = 4;
            int    v1       = 3;
            int    v2       = 2;
            string expected = "YES";
            string result   = Kangaroo.kangaroo(x1, v1, x2, v2);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 5
0
        public void TestCase1()
        {
            int    x1       = 0;
            int    x2       = 5;
            int    v1       = 2;
            int    v2       = 3;
            string expected = "NO";
            string result   = Kangaroo.kangaroo(x1, v1, x2, v2);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public void Kangaroo_has_correct_attributes()
        {
            //Arrange and Act
            Kangaroo kangaroo = new Kangaroo();

            //Assert
            string expectedFood = "I'll find some plants to eat!";

            Assert.Equal(expectedFood, kangaroo.FoodSearch());
            Assert.True(kangaroo.Marsupial);
            Assert.True(kangaroo.Swimmer);
            Assert.Equal("fight", kangaroo.FightOrFlight);
            Assert.Equal(8, kangaroo.SleepHours());
        }
Ejemplo n.º 7
0
        static void kangaroo()
        {
            string[] x1V1X2V2 = new string[] { "0", "3", "4", "2" };

            int x1 = Convert.ToInt32(x1V1X2V2[0]);
            int v1 = Convert.ToInt32(x1V1X2V2[1]);
            int x2 = Convert.ToInt32(x1V1X2V2[2]);
            int v2 = Convert.ToInt32(x1V1X2V2[3]);

            string result = Kangaroo.kangaroo(x1, v1, x2, v2);

            Console.WriteLine("Kangaroo");
            Console.WriteLine(result);
        }
Ejemplo n.º 8
0
        public void TestWinnerOutcome()
        {
            Kangaroo.StartingPosition1 = 0;
            Kangaroo.RacetrackLength1  = 50;
            int BettingAmount  = 45;
            int KangarooNumber = 1;
            int expectedWin    = 90;
            int expectedLose   = 0;

            Kangaroos[0] = new Kangaroo()
            {
                KangarooPictureBox = null
            };
            Kangaroos[1] = new Kangaroo()
            {
                KangarooPictureBox = null
            };
            Iqbal      = pFactory.getPunter("Iqbal", null, null);
            Iqbal.Cash = BettingAmount;
            Iqbal.PlaceBet((int)BettingAmount, KangarooNumber);

            bool nowin = true;
            int  win   = -1;

            while (nowin)
            {
                for (int i = 0; i < Kangaroos.Length; i++)
                {
                    if (Kangaroo.Run(Kangaroos[i]))
                    {
                        win = i + 1;
                        Iqbal.Collect(win);
                        nowin = false;
                    }
                }
            }
            if (Iqbal.bet.KangarooNum == win)
            {
                Assert.AreEqual(expectedWin, Iqbal.Cash, "Account not credited correctly");
            }
            if (Iqbal.bet.KangarooNum != win)
            {
                Assert.AreEqual(expectedLose, Iqbal.Cash, "Account not debited correctly");
            }
        }
        public static void Start()
        {
            PlayerBase playerA = new PlayerA();

            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            PlayerBase playerB = new PlayerB();

            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();

            Console.WriteLine("-------------With Decorators-----------");

            playerA = new Tiger(playerA);
            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            playerA = new Cheetah(playerA);
            playerA.PrintName();
            playerA.Attack();
            playerA.Jump();
            playerA.Run();

            playerB = new Kangaroo(playerB);
            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();

            playerB = new Tiger(playerB);
            playerB.PrintName();
            playerB.Attack();
            playerB.Jump();
            playerB.Run();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates an instance of the zoo class and configures it as the Como Zoo.
        /// </summary>
        private void CreateComoZoo()
        {
            // Create an instance of the Zoo class.
            this.comoZoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, 3640.25m, new Employee("Sam", 42), new Employee("Flora", 98), 3);

            // Add money to the animal snack machine.
            this.comoZoo.AnimalSnackMachine.AddMoney(42.75m);

            // Define an animal variable.
            Animal animal;

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dolly", 4, 35.3);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new Dingo and add him to the list of animals.
            animal = new Dingo("Dixie", 3, 33.8);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new platypus and add him to the list of animals.
            animal = new Platypus("Patty", 2, 15.5);

            animal.MakePregnant();

            this.comoZoo.AddAnimal(animal);

            // Create a new Hummingbird and add him to the list of animals.
            animal = new Hummingbird("Harold", 1, 0.5);

            this.comoZoo.AddAnimal(animal);

            // Create a new chimp and add him to the list of animals.
            animal = new Chimpanzee("Noah", 12, 500);

            this.comoZoo.AddAnimal(animal);

            // Create a new eagle and add him to the list of animals.
            animal = new Eagle("Tracy", 300, 10);

            this.comoZoo.AddAnimal(animal);

            // Create a new kangaroo and add him to the list of animals.
            animal = new Kangaroo("Jeff", 25, 30);

            this.comoZoo.AddAnimal(animal);

            // Create a new ostrich and add him to the list of animals.
            animal = new Ostrich("Jake", 40, 200);

            this.comoZoo.AddAnimal(animal);

            // Create a new shark and add him to the list of animals.
            animal = new Shark("Max", 23, 185);

            this.comoZoo.AddAnimal(animal);

            // Create a new squirrel and them to the list.
            animal = new Squirrel("Matt", 21, 200);

            this.comoZoo.AddAnimal(animal);

            // Create a guest.
            Guest guest = new Guest("Greg", 44, 150.35m, "Brown");

            // Add the guest and sell the ticket to the guest.
            this.comoZoo.AddGuest(guest, this.comoZoo.SellTicket(guest));

            // Create a guest.
            guest = new Guest("Darla", 11, 25.25m, "Salmon");

            // Add the guest and sell the ticket to the guest.
            this.comoZoo.AddGuest(guest, this.comoZoo.SellTicket(guest));
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            List <Kangaroo> kangaroos = new List <Kangaroo>();

            Kangaroo k1 = new Kangaroo
            {
                name   = "Jack",
                age    = 5,
                color  = "brown",
                gender = "M"
            };
            Kangaroo k2 = new Kangaroo
            {
                name   = "Lili",
                age    = 3,
                color  = "red",
                gender = "W"
            };

            kangaroos.Add(k1);
            kangaroos.Add(k2);

            //foreach (var item in kangaroos)
            //{
            //    Console.WriteLine(item);
            //}

            k1.PutInBox(k2);


            Console.WriteLine();
            k1.GetFromBox();

            Queue <int> qint = new Queue <int>();

            qint.Enqueue(2);
            qint.Enqueue(5);
            qint.Enqueue(6);
            qint.Enqueue(1);

            for (var i = 0; i < qint.Count; i++)
            {
                qint.Dequeue();
            }
            List <int> nums = new List <int>();

            nums.AddRange(new int[7] {
                1, 8, 3, 9, 20, 11, 0
            });

            //for (int i = 0; i < nums.Count; i++)
            //{
            //    nums[i] *= 10;
            //}

            nums.Sort();

            nums.Insert(2, 5);

            for (int i = 0; i < nums.Count; i++)
            {
                Console.Write(nums[i] + " ");
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            SortedMatrixSearch.Run();
            SparseSearch.Run();
            SearchInRotatedArray.Run();
            GroupAnagrams.Run();
            CombinationsOfNPairsParentheses.Run();
            PermutationWithDuplicates.Run();
            PermutationNoDuplicates.Run();

            var subsetList = new List <List <int> >();

            subsetList = SubsetInSet.FindAllSubsetInSet(new List <int> {
                1, 2, 3
            });
            ReverseLinkedList.Run();
            IsUniqueString.Run();
            StoneDivisionProblem.Run();
            Kangaroo.Run();
            AppleAndOrange.Run();
            AbbreviationProblem.Run();
            FibonacciModifiedProblem.Run();
            RecursiveDigitSum.Run();
            RangeSumOfBST.Run();
            GradingStudentsProblem.Run();
            // XorSequenceProblem.Run();
            CounterGameProblem.Run();
            MaximizingXORProblem.Run();
            LonelyIntegerProblem.Run();
            FlippingBitsProblem.Run();
            QueueUsingTwoStacksProblem.Run();
            GetNodeValue.Run();
            MergeTwoSortedLinkedLists.Run();
            Compare_Two_linked_lists.Run();

            DeleteNodeProblem.Run();
            ArrayManipulationProblem.Run();
            LeftRotationProblem.Run();
            HourGlass2D.Run();
            SimpleTextEditorProblem.Run();
            EqualStacksProblem.Run();
            MaximumElementProblem.Run();
            BinarySearchTreeInsertion.Run();
            TopViewProblem.Run();
            TimeConvertsionProblem.Run();
            BinaryTreePathsProblem.Run();
            IncreasingOrderSearchTree.Run();
            RemoveAllAdjacentDuplicatesInStringWithKLength.Run();
            RemoveAllAdjacentDuplicatesInString.Run();
            CheckStraightLineProblem.Run();
            HouseRobber.Run();
            UniquePathsProblem.Run();
            FirstUniqueCharacterInString.Run();
            BinaryTreeInorderTraversal.Run();
            DailyTemperaturesProblem.Run();
            CountingBitsproblem.Run();
            SortIntegersByTheNumberOf1BitsProblem.Run();
            HammingDistanceProblem.Run();
            RansomNoteProblem.Run();
            ConvertBinaryNumberInLinkedListToIntegerProblem.Run();
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            JewelsAndStones.Run();
            ClimbingStairsProblem.Run();
            BestTimeToBuyAndSellStock.Run();
            MajorityElementProblem.Run();
            MoveZeroesProblem.Run();
            InvertBinaryTree.Run();
            SingleNumberProblem.Run();
            MaximumDepthInTrree.Run();
            MergeTwoBinaryTrees.Run();
            AddBinaryProblem.Run();
            PlusOneProblem.Run();
            LengthOfLastWordProblem.Run();
            KadaneAlgorithmForMaxSubArray.Run();
            KMPAlgorithm.Run();
            CountAndSayProblem.Run();
            SearchInsertPosition.Run();
            ImplementIndexOfString.Run();
            RemoveElement.Run();
            RemoveDuplicatesFromSortedArray.Run();
            MergeTwoSortedLists.Run();
            ValidParentheses.Run();
            LongestCommonPrefix.Run();
            RomanToInteger.Run();
            PalindromeNumber.Run();
            ReverseInteger.Run();
            TwoSumProblem.Run();
            AddOneToNumber.Run();
            MostAmountOfChange.Run();
            #region BinaryTree
            LeastCommonAncestor.Run();
            PrintAllPaths.Run();
            HasPathSum.Run();
            CheckIfBinaryTreeIsBinarySearchTree.Run();
            PrintAllNodesWithRangeInBinarySearchTree.Run();
            UniqueTreeStructureNumber.Run();
            MirrorTree.Run();
            #region BitManuiplation_GetNthNumber
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            CountNumbersOf1InBit.Run();
            ReverseThebitsInInteger.Run();
            PrintBitsInInteger.Run();
            GetNthBit.Run();
            setNthBitTo1.Run();
            SetNthBitTo0.Run();
            #endregion
            MinimumtValueInTrree minValueInTree = new MinimumtValueInTrree();
            minValueInTree.Run();
            #endregion

            #region Recursion
            Chessboard chessboard = new Chessboard();
            chessboard.Run();
            RatPathToMaze ratPathToMaze = new RatPathToMaze();
            ratPathToMaze.Run();
            List <string> anagramList = new List <string>();
            anagramList        = WordAnagram.GenerateWordAnagram("abc");
            Pixel[,] pixelList = new Pixel[3, 3] {
                { new Pixel(0, 0, "red"), new Pixel(0, 1, "green"), new Pixel(0, 2, "green") },
                { new Pixel(1, 0, "red"), new Pixel(1, 1, "green"), new Pixel(1, 2, "green") },
                { new Pixel(2, 0, "red"), new Pixel(2, 1, "green"), new Pixel(2, 2, "green") }
            };
            FillPaint.PaintFill(pixelList, 1, 2, "green", "black");

            BinaryTreesAreTheSame.Run();

            #endregion

            #region General problems
            RotateArrayByKSpaces.Run();

            #region AddtwoNumbersReferencedByTheirDigits
            var addRes = AddtwoNumbersReferencedByTheirDigits.AddNumbers(new int[] { 1, 2, 7 }, new int[] { 9, 4 });
            #endregion

            #region RunLengthEncoding
            var encodedStr = RunLengthEncoding.Encode("aabbbbc");
            var decodedStr = RunLengthEncoding.Decode(encodedStr);
            #endregion

            #region BreakDocumentIntoChunk
            var chunkRes = BreakDocumentIntoChunk.Chunkify("ab:dd:ddfcct:aab:cccc", ':', 5);
            #endregion

            #region GameOfLife
            var gameRes = GameOfLife.GetNextInteration(new int[3, 3] {
                { 1, 0, 0 }, { 0, 1, 1 }, { 1, 0, 0 }
            });
            #endregion .

            #endregion


            #region InsertionSort
            InsertionSort.insertionSort(listToSort);
            #endregion

            #region BinarySearch
            Console.WriteLine(String.Format("%s is present at index: %s", 30, BinarySearch.binarySearch(sortedArray, 30, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 4, BinarySearch.binarySearch(sortedArray, 4, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 15, BinarySearch.binarySearch(sortedArray, 15, 0, sortedArray.Length - 1)));
            #endregion


            #region MergeSort
            MergeSort.print(listToSort);
            MergeSort.mergeSort(listToSort);
            #endregion


            #region QuickSort
            QuickSort.print(listToSort);
            QuickSort.quickSort(listToSort, 0, listToSort.Length - 1);
            QuickSort.print(listToSort);
            #endregion
        }
Ejemplo n.º 13
0
 public virtual void SetUp()
 {
     _challenge = new Kangaroo();
 }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            // WHERE THE APPLICATION RUNS OR STARTS AKA (Entry Point)

            var bpl        = new Library("BPL");
            var jakesBooks = new Library("Jake");
            var mobyDick   = new Book("Moby Dick", "Herman Melville", "BPL", true);


            var petStore = new List <Animal>();


            var fido = new Dog()
            {
                Name = "Fido"
            };


            fido.Sleep("2");
            Console.WriteLine(fido.Legs);
            petStore.Add(fido);

            var garfield = new Cat()
            {
                IsEvil = false,
                Legs   = 2
            };

            garfield.Breath();
            petStore.Add(garfield);

            var joey = new Kangaroo()
            {
                ChampionBoxer = true
            };

            joey.Cute = true;

            petStore.Add(joey);


            foreach (var x in petStore)
            {
                x.Sleep("8");
            }



            Book wow = new Book("War of the Worlds", "HG Wells", "BPL", true);

            bpl.Books.Add(mobyDick);
            bpl.Books.Add(wow);
            jakesBooks.Books.Add(new Book("Head First with C#", "That one dude", "Jake"));

            var playing = true;

            while (playing)
            {
                Console.Clear();
                Console.WriteLine("What would you like to do?");
                Console.WriteLine(@"
          1. Go To BP Library
          2. Look at your own books
          3. Quit
        ");

                var userChoice = Console.ReadLine();


                if (userChoice == "1")
                {
                    bpl.Checkout(jakesBooks);
                }
                if (userChoice == "2")
                {
                    jakesBooks.Checkout(bpl);
                }
                if (userChoice == "3")
                {
                    playing = false;
                }
                if (userChoice == "4")
                {
                    Console.WriteLine("Congrats you've activated skynet... Prepare to Die");
                    Thread.Sleep(1000);
                    Console.Beep();
                    Console.WriteLine("3");
                    Thread.Sleep(1000);
                    Console.Beep();
                    Console.WriteLine("2");
                    Thread.Sleep(1000);
                    Console.Beep();
                    Console.WriteLine("1");
                    Thread.Sleep(1000);
                    Console.Beep();
                    Console.WriteLine("Goodbye");
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.ForegroundColor = ConsoleColor.White;
                    var i = 0;
                    while (i < 50)
                    {
                        Console.WriteLine(@"
                    HAHAHA 
                              HAHAHA 
                  HAHAHA
            ");
                        Thread.Sleep(300);
                        i++;
                    }
                    playing = false;
                }
            }



            // Console.WriteLine("Okay here we go");
            // List<int> nums1 = new List<int>(); // LEARN ABOUT THIS LATER BOXING UNBOXING
            // int[] nums2 = new int[100000000];


            // var stopwatch = new Stopwatch();
            // stopwatch.Start();

            // for(var i = 0; i < nums2.Length; i++)
            // {
            //   nums2[i] = i;
            //   // Console.WriteLine(nums2[i]);
            // }
            // stopwatch.Stop();
            // Console.WriteLine($"That only took {stopwatch.ElapsedMilliseconds}");
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Zoo!\n");

            Parrot p = new Parrot("Vasyz", 5, "Red");
            //Parrot p2 = new Parrot("Valera", 1, "White");


            //Animals["102"].name = "Kolya";

            ////Console.WriteLine(Animals.ContainsKey("102"));
            ////Console.WriteLine(Animals.ContainsKey("105"));


            //// Console.WriteLine(Animals.ContainsValue(p2));

            //Animals.Remove("102");

            //foreach (var item in Animals)
            //{
            //    Console.WriteLine(item.Key);
            //    Console.WriteLine(item.Value.name);
            //    Console.WriteLine(item.Value.color);
            //    Console.WriteLine();
            //}


            List <Kangaroo> kangaroos = new List <Kangaroo>();

            Kangaroo k1 = new Kangaroo
            {
                name   = "Jack",
                age    = 5,
                color  = "brown",
                gender = "M"
            };
            Kangaroo k2 = new Kangaroo
            {
                name   = "Lili",
                age    = 3,
                color  = "red",
                gender = "W"
            };

            kangaroos.Add(k1);
            kangaroos.Add(k2);

            //foreach (var item in kangaroos)
            //{
            //    Console.WriteLine(item);
            //}

            k1.PutInBox(k2);
            k1.PutInBox(p);

            Console.WriteLine();
            k1.GetFromBox();

            Queue <int> qint = new Queue <int>();

            qint.Enqueue(2);
            qint.Enqueue(5);
            qint.Enqueue(6);
            qint.Enqueue(1);

            for (var i = 0; i < qint.Count; i++)
            {
                qint.Dequeue();
            }
            //List<int> nums = new List<int>();

            //nums.AddRange(new int[7] { 1, 8, 3, 9, 20, 11, 0 });

            ////for (int i = 0; i < nums.Count; i++)
            ////{
            ////    nums[i] *= 10;
            ////}

            //nums.Sort();

            //nums.Insert(2, 5);

            //for (int i = 0; i < nums.Count; i++)
            //{
            //    Console.Write(nums[i]+ " ");
            //}
        }