From d7549b4eedf679e5fea805cb296bff1726eb5e86 Mon Sep 17 00:00:00 2001 From: Marcus Palm Date: Wed, 10 Jan 2024 15:09:52 +0100 Subject: [PATCH 1/2] Marcus Palm csharp-fundamentals-methods --- csharp-fundamentals-methods.Main/Core.cs | 28 +++++++++++++++---- csharp-fundamentals-methods.Main/Extension.cs | 4 ++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..89efe4e 100644 --- a/csharp-fundamentals-methods.Main/Core.cs +++ b/csharp-fundamentals-methods.Main/Core.cs @@ -27,7 +27,9 @@ 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(); + //throw new NotImplementedException(); + string greeting = $"Hello {name}!"; + 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(); + //throw new NotImplementedException(); + return number +1 ; } //TODO: 3. Construct a friendly greeting @@ -50,7 +53,9 @@ Complete this method so that it accepts a name as an input and outputs a friendl */ public string happilyGreet(string name) { - throw new NotImplementedException(); + //throw new NotImplementedException(); + string happyGreet = $"Hi, {name} :)"; + return happyGreet; } @@ -69,8 +74,12 @@ 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 +101,14 @@ 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 -1; i++) + { + sb.Append("!"); + } + return sb.ToString(); } diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index a4461e2..26d67ef 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -17,9 +17,11 @@ 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(); + + } From d67a7996677cfa4647137cc4b175f393afaa9f51 Mon Sep 17 00:00:00 2001 From: Marcus Palm Date: Tue, 5 Mar 2024 08:17:11 +0100 Subject: [PATCH 2/2] marcus palm extensions --- csharp-fundamentals-methods.Main/Extension.cs | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index 26d67ef..ffa83d4 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -17,10 +17,22 @@ 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 string timerStatus(int v) + public string timerStatus(int minutes) { - throw new NotImplementedException(); - + //throw new NotImplementedException(); + if (minutes < 0) + { + return "The timer finished ages ago!"; + } + else if (minutes > 0) + { + return "The cake is still baking!"; + } + else + { + return "The cake is ready!"; + } + } @@ -35,9 +47,21 @@ provided and the prep time per ingredient. If a prep time of 0 is provided, the method should assume each ingredient takes 2 minutes to prepare. */ - public double estimatePrepTime(string[] strings, int v) + public double estimatePrepTime(string[] ingredients, int time) { - throw new NotImplementedException(); + //throw new NotImplementedException(); + int totalTime = 0; + foreach (string ingredient in ingredients) + { + totalTime = totalTime + time; + } + + if (totalTime == 0) + { + totalTime = 2 * ingredients.Length; + } + + return totalTime; } @@ -51,9 +75,18 @@ public double estimatePrepTime(string[] strings, int v) The method should return the number of grams of sugar needed to make the cake. */ - public double calculateGramsOfSugar(string[] strings, int v) + public double calculateGramsOfSugar(string[] ingredients, int time) { - throw new NotImplementedException(); + //throw new NotImplementedException(); + + if (ingredients.Contains("sugar")) + { + return 100 * time; + } + else + { + return 0; + } }