From 238d661f2ac577351e96a2991ed479680875903e Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 10 Jan 2024 09:25:51 +0100 Subject: [PATCH] Solved core TODO --- csharp-fundamentals-methods.Main/Core.cs | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..feffeba 100644 --- a/csharp-fundamentals-methods.Main/Core.cs +++ b/csharp-fundamentals-methods.Main/Core.cs @@ -27,7 +27,7 @@ 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(); + return $"Hello {name}!"; } //TODO: 2. Increment a number @@ -36,7 +36,7 @@ Complete this method so that it increases the number given by 1 and returns the */ public int increment(int number) { - throw new NotImplementedException(); + return number += 1; } //TODO: 3. Construct a friendly greeting @@ -50,7 +50,7 @@ Complete this method so that it accepts a name as an input and outputs a friendl */ public string happilyGreet(string name) { - throw new NotImplementedException(); + return $"Hi, {name} :)"; } @@ -69,11 +69,13 @@ Create a method named constructNumberArray that accepts two whole numbers named public int[] constructNumberArray(int lower, int upper) { - - int[] resultArray = { }; - + List result = new List(); + for(int i = lower; i <= upper; i++) + { + result.Add(i); + } + int[] resultArray = result.ToArray(); return resultArray; - } @@ -92,7 +94,15 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + phrase = phrase.ToUpper(); + StringBuilder sb = new StringBuilder(); + sb.Append(phrase); + for(int i = 0; i < number; i++) + { + sb.Append("!"); + } + + return $"{sb}"; }