From eaf8b773c098ccf62c76a59d2c0ffe0d9f2b5cc1 Mon Sep 17 00:00:00 2001 From: Jacob Chen Jensen Date: Wed, 10 Jan 2024 10:27:29 +0100 Subject: [PATCH] core and extension --- csharp-fundamentals-methods.Main/Core.cs | 23 ++++++++--- csharp-fundamentals-methods.Main/Extension.cs | 41 ++++++++++++++++--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/csharp-fundamentals-methods.Main/Core.cs b/csharp-fundamentals-methods.Main/Core.cs index a69b542..ee3ff05 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,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]; + int increm = 0; + for(int i = 0; i < upper-lower+1; i++) + { + resultArray[i] = lower+increm; + increm += 1; + } return resultArray; @@ -92,7 +98,14 @@ The number of exclamation marks appended must be determined by the number provid public string shout(string phrase, int number) { - return $""; + string upper = phrase.ToUpper(); + string exclam = ""; + for(int i = 0; i < number; i++) + { + exclam = exclam+"!"; + } + + return upper+exclam; } diff --git a/csharp-fundamentals-methods.Main/Extension.cs b/csharp-fundamentals-methods.Main/Extension.cs index a4461e2..84a1e37 100644 --- a/csharp-fundamentals-methods.Main/Extension.cs +++ b/csharp-fundamentals-methods.Main/Extension.cs @@ -17,9 +17,24 @@ 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 still baking!"; + } + else if(v < 0) + { + return "The timer finished ages ago!"; + } + else if(v == 0) + { + return "The cake is ready!"; + } else + { + return ""; + } + } @@ -33,9 +48,16 @@ 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(); + int prep = v; + if (v == 0) + { + prep = 2; + }; + + return prep * strings.Length; + } @@ -49,9 +71,16 @@ 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 int calculateGramsOfSugar(string[] strings, int v) { - throw new NotImplementedException(); + if (strings.Contains("sugar")) + { + return v * 100; + } + else + { + return 0; + }; }