From 1f1beee2fbc75d830b8aa4167ed98b6ef4910188 Mon Sep 17 00:00:00 2001 From: Martin Vu Date: Tue, 7 Jan 2025 15:34:48 +0100 Subject: [PATCH] finished exercise --- .github/workflows/extended-criteria-tests.yml | 2 +- .github/workflows/standard-criteria-tests.yml | 2 +- csharp-fundamentals-control-flow.Main/Core.cs | 106 +++++++++++++++--- 3 files changed, 95 insertions(+), 15 deletions(-) diff --git a/.github/workflows/extended-criteria-tests.yml b/.github/workflows/extended-criteria-tests.yml index cab7448..85f8c84 100644 --- a/.github/workflows/extended-criteria-tests.yml +++ b/.github/workflows/extended-criteria-tests.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '8.0.x' + dotnet-version: '9.0.x' # 3) Restore the dependencies and tools of a project or solution. - name: Install dependencies run: dotnet restore diff --git a/.github/workflows/standard-criteria-tests.yml b/.github/workflows/standard-criteria-tests.yml index 54bb2f1..7a54ec3 100644 --- a/.github/workflows/standard-criteria-tests.yml +++ b/.github/workflows/standard-criteria-tests.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '8.0.x' + dotnet-version: '9.0.x' # 3) Restore the dependencies and tools of a project or solution. - name: Install dependencies run: dotnet restore diff --git a/csharp-fundamentals-control-flow.Main/Core.cs b/csharp-fundamentals-control-flow.Main/Core.cs index 9fe1a9d..0a6b5fb 100644 --- a/csharp-fundamentals-control-flow.Main/Core.cs +++ b/csharp-fundamentals-control-flow.Main/Core.cs @@ -48,61 +48,89 @@ 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 +138,14 @@ 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,14 +154,36 @@ public bool ten(string sentence) // Otherwise, return the number 0. public int eleven(string sentence) { - throw new NotImplementedException(); + if (sentence.Contains("milk") && sentence.Contains("coffee")) + { + return 9; + } + else if (sentence.Contains("coffee")) + { + return 6; + } + else if (sentence.Contains("milk")) + { + return 3; + } + else + { + 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; + } + else + { + return false; + } } /* @@ -141,7 +198,30 @@ public bool twelve(int num, int lower, int upper) */ public string thirteen(int age) { - throw new NotImplementedException(); + if (age == 0) + { + return "Baby"; + } + else if (age >= 1 && age <= 4) + { + return "Toddler"; + } + else if (age >= 5 && age <= 12) + { + return "Child"; + } + else if (age >= 13 && age <= 19) + { + return "Teenager"; + } + else if (age >= 20) + { + return "Adult"; + } + else + { + return ""; + } } } }