From 6b9e1b694340af6a7fbc1a44c89c4ba277e4aaaf Mon Sep 17 00:00:00 2001 From: Rose Breedveld Date: Fri, 2 Feb 2024 10:26:43 +0100 Subject: [PATCH] Rose Breedveld, fundamentals control flow core and extentions passed --- csharp-fundamentals-control-flow.Main/Core.cs | 86 +++++++++++++++---- .../Extension.cs | 28 ++++-- 2 files changed, 94 insertions(+), 20 deletions(-) diff --git a/csharp-fundamentals-control-flow.Main/Core.cs b/csharp-fundamentals-control-flow.Main/Core.cs index 9fe1a9d..1f7c83c 100644 --- a/csharp-fundamentals-control-flow.Main/Core.cs +++ b/csharp-fundamentals-control-flow.Main/Core.cs @@ -48,61 +48,83 @@ public string sayGoodMorning(bool isMorning) // Change the returned value in the method below to your answer. It is case-sensitive. public string one() { - return ""; + return "Good day!"; } //TODO: 2. What will the output be if I run sayGoodMorning(true)? // Change the returned value in the method below to your answer. It is case-sensitive. public string two() { - return ""; + return "Good morning!"; } //TODO: 3. What will the output be if I run sayGoodMorning("Hello" == "Hello")? // Change the returned value in the method below to your answer. It is case-sensitive. public string three() { - return ""; + return "Good morning!"; } //TODO: 4. What will the output be if I run sayGoodMorning("A word" != "Another word") public string four() { - return ""; + return "Good morning!"; } // 5. What will the output be if I run sayGoodMorning(25 != 25) public string five() { - return ""; + return "Good day!"; } //TODO: 6. Use a conditional statement to return "Correct!" if the input is more than 7 // or "Wrong!" if not public string six(int num) { - throw new NotImplementedException(); + if (num > 7 ) + { + return "Correct!"; + } else + { + return "Wrong!"; + } } //TODO: 7. Use a conditional statement to return "Correct!" if the input is false // or "Wrong!" if not public string seven(bool boolean) { - throw new NotImplementedException(); + if (!boolean) + { + return "Correct!"; + + } else { return "Wrong!"; } } //TODO: 8. Use a conditional statement to return "Correct!" if numOne is more than or equal to numTwo // or "Wrong!" if not public string eight(int numOne, int numTwo) { - throw new NotImplementedException(); + if (numOne >= numTwo) + { + return "Correct!"; + } else + { + return "Wrong!"; + } } //TODO: 9. Use a conditional statement to return true if the array provided is not empty // or false if it is empty public bool nine(int[] nums) { - throw new NotImplementedException(); + if (nums.Length != 0) + { + return true; + } else + { + return false; + } } //TODO: 10. Use a conditional statement to return true if the provided string contains the word @@ -110,7 +132,13 @@ public bool nine(int[] nums) // https://www.w3schools.com/java/java_ref_string.asp public bool ten(string sentence) { - throw new NotImplementedException(); + if (sentence.Contains("milk")) + { + return true; + } else + { + return false; + } } //TODO: 11. Use conditional statements to return the number 3 if the provided string contains @@ -119,18 +147,34 @@ public bool ten(string sentence) // Otherwise, return the number 0. public int eleven(string sentence) { - throw new NotImplementedException(); + if (sentence.Contains("coffee") && sentence.Contains("milk")) + { + return 9; + } else if (sentence.Contains("coffee")) + { + return 6; + } else if (sentence.Contains("milk")) + { + return 3; + } + return 0; + + } //TODO: 12. Use conditional statements to return true if num is more than or equal to lower and is // less than or equal to upper, otherwise return false. public bool twelve(int num, int lower, int upper) { - throw new NotImplementedException(); + if(num >= lower && num <= upper) + { + return true; + } + return false; } /* - 12. Use conditional statements to return a string based on what the age parameter is. + 13. Use conditional statements to return a string based on what the age parameter is. The table below shows the string that should be returned for each range of values that age can be. For example: If age is 3, you should return "Toddler" 0 | Baby @@ -139,9 +183,21 @@ public bool twelve(int num, int lower, int upper) 13-19 | Teenager 20+ | Adult */ - public string thirteen(int age) + public string thirteen(int age) { - throw new NotImplementedException(); + switch (age) + { + case 0: + return("Baby"); + case <= 4: + return("Toddler"); + case <= 12: + return ("Child"); + case <= 19: + return("Teenager"); + default: + return ("Adult"); + } } } } diff --git a/csharp-fundamentals-control-flow.Main/Extension.cs b/csharp-fundamentals-control-flow.Main/Extension.cs index 08108e2..2897ed6 100644 --- a/csharp-fundamentals-control-flow.Main/Extension.cs +++ b/csharp-fundamentals-control-flow.Main/Extension.cs @@ -20,7 +20,15 @@ public class Extension */ public string timerStatus(int minutes) { - throw new NotImplementedException(); + if (minutes == 0) + { + return "The cake is ready!"; + } else if (minutes > 0){ + return "The cake is still baking!"; + } else + { + return "The timer finished ages ago!"; + } } @@ -35,8 +43,13 @@ provided and the prep time per ingredient. public int estimatePrepTime(string[] ingredients, int time) - { - throw new NotImplementedException(); + { + int prepTime = time; + if (time == 0) + { + prepTime += 2; + } + return prepTime * ingredients.Length; } //TODO: 3. Create a method named calculateGramsOfSugar that accepts two parameters: @@ -46,9 +59,14 @@ public int estimatePrepTime(string[] ingredients, int time) The method should return the number of grams of sugar needed to make the cake. */ - public int calculateGramsOfSugar(string[] ingredients, int time) + public int calculateGramsOfSugar(string[] ingredients, int layers) { - throw new NotImplementedException(); + if (ingredients.Contains("sugar")) + { + return layers * 100; + } + // default return statement of 0, if sugar is not in the list of ingredients. + return 0; } } }