From b625049ca06bd5ddf5b67a097c1f3bd1082d8964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wullum?= Date: Tue, 7 Jan 2025 15:43:51 +0100 Subject: [PATCH] finished excercise --- csharp-fundamentals-control-flow.Main/Core.cs | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/csharp-fundamentals-control-flow.Main/Core.cs b/csharp-fundamentals-control-flow.Main/Core.cs index 9fe1a9d..b76b756 100644 --- a/csharp-fundamentals-control-flow.Main/Core.cs +++ b/csharp-fundamentals-control-flow.Main/Core.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -48,39 +49,41 @@ 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) { + if (num > 7) { return "Correct!"; } else { return "Wrong!"; }; + throw new NotImplementedException(); } @@ -88,6 +91,8 @@ public string six(int num) // or "Wrong!" if not public string seven(bool boolean) { + if (!boolean) { return "Correct!"; } else { return "Wrong!"; }; + throw new NotImplementedException(); } @@ -95,6 +100,8 @@ public string seven(bool boolean) // or "Wrong!" if not public string eight(int numOne, int numTwo) { + if (numOne >= numTwo) { return "Correct!"; } else { return "Wrong!"; }; + throw new NotImplementedException(); } @@ -102,6 +109,8 @@ public string eight(int numOne, int numTwo) // or false if it is empty public bool nine(int[] nums) { + return nums.Length > 0; + throw new NotImplementedException(); } @@ -110,6 +119,8 @@ public bool nine(int[] nums) // https://www.w3schools.com/java/java_ref_string.asp public bool ten(string sentence) { + return sentence.Contains("milk"); + throw new NotImplementedException(); } @@ -119,6 +130,20 @@ public bool ten(string sentence) // Otherwise, return the number 0. public int eleven(string sentence) { + if (sentence.Contains("milk") && sentence.Contains("coffee")) + { + return 9; + } + else if (sentence.Contains("milk")) + { + return 3; + } + else if (sentence.Contains("coffee")) + { + return 6; + } + else return 0; + throw new NotImplementedException(); } @@ -126,6 +151,8 @@ public int eleven(string sentence) // less than or equal to upper, otherwise return false. public bool twelve(int num, int lower, int upper) { + return ((num <= upper) && (num >= lower)); + throw new NotImplementedException(); } @@ -141,6 +168,15 @@ public bool twelve(int num, int lower, int upper) */ public string thirteen(int age) { + + if (age < 1) { return "Baby"; } + else if (age > 0 && age < 5) { return "Toddler"; } + else if (age > 4 && age < 13) { return "Child"; } + else if (age > 12 && age < 20) { return "Teenager"; } + else if (age > 19) { return "Adult"; } + else return "No"; + + throw new NotImplementedException(); } }