From 32cea95b28e483193ad338ac4003fe7d110c0e10 Mon Sep 17 00:00:00 2001 From: Kristian Date: Wed, 10 Jan 2024 10:01:31 +0100 Subject: [PATCH 1/3] solution --- csharp-fundamentals-methods.Main/Core.cs | 10 +++--- csharp-fundamentals-methods.Main/Extension.cs | 31 ++++++++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..07c4f99 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} :)"; } @@ -70,7 +70,7 @@ Create a method named constructNumberArray that accepts two whole numbers named public int[] constructNumberArray(int lower, int upper) { - int[] resultArray = { }; + int[] resultArray = Enumerable.Range(lower, upper-lower+1).ToArray(); return resultArray; @@ -92,7 +92,7 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + return $"{phrase.ToUpper()}{new string('!', number)}"; } diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index a4461e2..1dff9d7 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; @@ -17,9 +18,21 @@ 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(); + switch (v) + { + case var expression when v > 0: + return "The cake is still baking!"; + break; + case var expression when v < 0: + // code block + return "The timer finished ages ago!"; + break; + default: + return "The cake is ready!"; + } + } @@ -33,9 +46,13 @@ 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 int estimatePrepTime(string[] strings, int v) { - throw new NotImplementedException(); + if (v > 0) { + return v * strings.Length; + } else { + return 2 * strings.Length; + } } @@ -51,7 +68,11 @@ public double estimatePrepTime(string[] strings, int v) public double calculateGramsOfSugar(string[] strings, int v) { - throw new NotImplementedException(); + if (strings.Contains("sugar")) { + return v * 100D; + } else { + return 0; + } } From 5ca885b48df795922fc0ef948e887296e9bfbc34 Mon Sep 17 00:00:00 2001 From: Kristian Date: Wed, 10 Jan 2024 10:03:30 +0100 Subject: [PATCH 2/3] . --- csharp-fundamentals-methods.Main/Extension.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index 1dff9d7..61b5e78 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -46,10 +46,10 @@ 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 int estimatePrepTime(string[] strings, int v) + public double estimatePrepTime(string[] strings, int v) { if (v > 0) { - return v * strings.Length; + return Convert.ToDouble(v * strings.Length); } else { return 2 * strings.Length; } From 9632818c25c580e3c13d5cc988697b0506be2c59 Mon Sep 17 00:00:00 2001 From: Kristian Date: Wed, 10 Jan 2024 10:33:20 +0100 Subject: [PATCH 3/3] . --- csharp-fundamentals-methods.Main/Extension.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index 61b5e78..947d0b7 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -26,7 +26,6 @@ public string timerStatus(int v) return "The cake is still baking!"; break; case var expression when v < 0: - // code block return "The timer finished ages ago!"; break; default: