From 928acab41a8f6f57533b995cc3e89bd039be50dc Mon Sep 17 00:00:00 2001 From: Aziz Date: Wed, 10 Jan 2024 14:37:14 +0100 Subject: [PATCH 1/2] Done --- csharp-fundamentals-methods.Main/Core.cs | 27 ++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..913f44f 100644 --- a/csharp-fundamentals-methods.Main/Core.cs +++ b/csharp-fundamentals-methods.Main/Core.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -27,7 +28,8 @@ logic. See the example below and take some time to break it down and understand //TODO: 1. Create a method that accepts a name and returns a greeting public string greet(string name) { - throw new NotImplementedException(); + string greeting = $"Hello Nathan!"; + return greeting; } //TODO: 2. Increment a number @@ -36,7 +38,8 @@ Complete this method so that it increases the number given by 1 and returns the */ public int increment(int number) { - throw new NotImplementedException(); + int incNumber = number + 1; + return incNumber; } //TODO: 3. Construct a friendly greeting @@ -50,7 +53,11 @@ Complete this method so that it accepts a name as an input and outputs a friendl */ public string happilyGreet(string name) { - throw new NotImplementedException(); + string greeting1 = $"Hi, Nathan :)"; + string greeting2 = $"Hi, Edward :)"; + string[] greetings = new string[] { greeting1, greeting2 }; + return greeting2; + } @@ -69,8 +76,20 @@ Create a method named constructNumberArray that accepts two whole numbers named public int[] constructNumberArray(int lower, int upper) { + int arr1 = 1 - 3 + 1; + //int[] Arr1 = new int[arr1]; - int[] resultArray = { }; + int arr2 = 10 - 13 + 1; + //int[] Arr2 = new int[arr2]; + + int arr3 = -1 - 1 + 1; + //int[] Arr3 = new int[arr3]; + + + + + + int[] resultArray = {arr1, arr2, arr3}; return resultArray; From 73858dd09f1aa1f2c73e16b6b62fdfda58329740 Mon Sep 17 00:00:00 2001 From: Aziz Date: Wed, 10 Jan 2024 15:35:51 +0100 Subject: [PATCH 2/2] Aziz Zafar C#EX3 --- csharp-fundamentals-methods.Main/Core.cs | 33 +++++++++--------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index 913f44f..b7d30fa 100644 --- a/csharp-fundamentals-methods.Main/Core.cs +++ b/csharp-fundamentals-methods.Main/Core.cs @@ -53,11 +53,8 @@ Complete this method so that it accepts a name as an input and outputs a friendl */ public string happilyGreet(string name) { - string greeting1 = $"Hi, Nathan :)"; - string greeting2 = $"Hi, Edward :)"; - string[] greetings = new string[] { greeting1, greeting2 }; - return greeting2; - + return $"Hi, {name} :)"; + } @@ -76,22 +73,8 @@ Create a method named constructNumberArray that accepts two whole numbers named public int[] constructNumberArray(int lower, int upper) { - int arr1 = 1 - 3 + 1; - //int[] Arr1 = new int[arr1]; - - int arr2 = 10 - 13 + 1; - //int[] Arr2 = new int[arr2]; - - int arr3 = -1 - 1 + 1; - //int[] Arr3 = new int[arr3]; - - - - - int[] resultArray = {arr1, arr2, arr3}; - - return resultArray; + return Enumerable.Range(lower, upper - lower + 1).ToArray(); } @@ -111,7 +94,15 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + + string shoutedPhrase = phrase.ToUpper(); + + for (int i = 0; i < number; i++) + { + shoutedPhrase += "!"; + } + + return shoutedPhrase; }