From 01d601d4128ef27acf6ce61f5487bd702f319312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisabeth=20R=C3=B8ysland?= Date: Fri, 8 Aug 2025 15:19:16 +0200 Subject: [PATCH] =?UTF-8?q?All=20tests=20passed,=20Elisabeth=20R=C3=B8ysla?= =?UTF-8?q?nd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csharp-fundamentals-methods.Main/Core.cs | 22 ++++++++++--- csharp-fundamentals-methods.Main/Extension.cs | 32 +++++++++++++++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index aad1694..b6060f5 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 + " :)"; } //TODO: 4. Construct an array of numbers @@ -67,7 +67,12 @@ 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 = 0; i <= (upper-lower); i++) + { + resultArray[i] = lower + i; + } return resultArray; } @@ -86,7 +91,14 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + string exclamationPoints = "!"; + + for (int i = 1; i <= number-1; i++) + { + exclamationPoints += "!"; + } + + return $"{phrase.ToUpper()}{exclamationPoints}"; } } } diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index f7a9b9a..a1417db 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -20,7 +20,18 @@ public class Extension */ public string timerStatus(int timeLeftInMin) { - throw new NotImplementedException(); + if (timeLeftInMin == 0) + { + return "The cake is ready!"; + } + else if (timeLeftInMin > 0) + { + return "The cake is still baking!"; + } + else + { + return "The timer finished ages ago!"; + } } //TODO: Extension 2: Estimate Prep Time @@ -35,7 +46,16 @@ provided and the prep time per ingredient. public double estimatePrepTime(string[] ingredients, int prepTimePerIngredient) { - throw new NotImplementedException(); + double prepTime = ingredients.Length * prepTimePerIngredient; + + if (prepTime == 0) + { + return ingredients.Length * 2; + } + else + { + return prepTime; + } } //TODO: Extension 3: calculateGramsOfSugar that accepts two parameters 1 an array of ingredients that will always contain 3 ingredients AND 2 the number of layers the cake has. The cake will need 100g of sugar per layer, if that ingredient is present in the provided list of ingredients. The method should return the number of grams of sugar needed to make the cake. @@ -49,7 +69,13 @@ public double estimatePrepTime(string[] ingredients, int prepTimePerIngredient) public double calculateGramsOfSugar(string[] ingredients, int numberOfCakeLayers) { - throw new NotImplementedException(); + + if (ingredients.Contains("sugar")) + { + return Convert.ToDouble(numberOfCakeLayers * 100); + } + + return 0; } } }