diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..d650763 100644 --- a/csharp-fundamentals-methods.Main/Core.cs +++ b/csharp-fundamentals-methods.Main/Core.cs @@ -27,31 +27,38 @@ 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 /* Complete this method so that it increases the number given by 1 and returns the result */ public int increment(int number) - { - throw new NotImplementedException(); - } + { + + return number + 1; + } - //TODO: 3. Construct a friendly greeting - /* - Complete this method so that it accepts a name as an input and outputs a friendly greeting - with a smiley face. Example input and output: - Input | Output - -------|------- - Nathan | Hi, Nathan :) - Edward | Hi, Edward :) - */ - public string happilyGreet(string name) + //TODO: 3. Construct a friendly greeting + /* + Complete this method so that it accepts a name as an input and outputs a friendly greeting + with a smiley face. Example input and output: + Input | Output + -------|------- + Nathan | Hi, Nathan :) + Edward | Hi, Edward :) + */ + public string happilyGreet(string name) { - throw new NotImplementedException(); - } + + return $"Hi, {name} :)"; + + + } @@ -70,9 +77,13 @@ Create a method named constructNumberArray that accepts two whole numbers named public int[] constructNumberArray(int lower, int upper) { - int[] resultArray = { }; + int[] resultArray = new int[upper - lower + 1]; + for (int i = lower, j = 0; i <= upper; i++, j++) + { + resultArray[j] = i; + } - return resultArray; + return resultArray; } @@ -92,7 +103,13 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + string shouted = phrase.ToUpper(); + + shouted += new string('!', number); + + return shouted; + + } diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index a4461e2..0da1d9a 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -17,9 +17,20 @@ public class Extension "The cake is still baking!" if there are any remaining minutes left, and "The timer finished ages ago!" if the remaining minutes is a negative number */ - public double timerStatus(int v) + public string timerStatus(int v) { - throw new NotImplementedException(); + if (v == 0) + { + return "The cake is ready!"; + } + else if (v > 0) + { + return "The cake is still baking!"; + } + else + { + return "The timer finished ages ago!"; + } } @@ -35,7 +46,14 @@ provided and the prep time per ingredient. public double estimatePrepTime(string[] strings, int v) { - throw new NotImplementedException(); + if (v == 0) + { + v = 2; + } + + int time = strings.Length * v; + + return time; } @@ -51,7 +69,12 @@ public double estimatePrepTime(string[] strings, int v) public double calculateGramsOfSugar(string[] strings, int v) { - throw new NotImplementedException(); + string Sugar = "sugar"; + bool hasSugar = strings.Contains(Sugar); + + double SugarPerLayer = hasSugar ? 100 : 0; + double totalSugar = SugarPerLayer * v; + return totalSugar; }