Skip to content

Commit 0025141

Browse files
committed
Adding problem 6 from Final Spring 2026.
1 parent 67511b4 commit 0025141

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
class Program
4+
{
5+
static void Main()
6+
{
7+
string stringtest;
8+
bool booltest = Demo.UserFoundSecretWord(out stringtest);
9+
Console.WriteLine("The method returned " + booltest + " after you entered \"" + stringtest + "\".");
10+
}
11+
}
12+
13+
public static class Demo{
14+
// Beginning of solution.
15+
public static bool UserFoundSecretWord(out string uInput){
16+
Console.WriteLine("Enter a string");
17+
uInput = Console.ReadLine();
18+
if(uInput == null) throw new ArgumentNullException();
19+
return uInput.Contains("scytale");
20+
}
21+
// End of solution.
22+
}

source/solutions/oop/references.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ tags:
120120

121121
## Problems
122122

123+
#. Knowing that our secret word is "[scytale](https://en.wikipedia.org/wiki/Scytale)", write a `UserFoundSecretWord` method that
124+
125+
- asks the user for a `string`,
126+
- throws an `ArgumentNullException` exception if the string entered is `null`,
127+
- returns `true` if the string entered contains `"scytale"`, `false` otherwise,
128+
- stores the string entered in the `uInput` reference variable.
129+
130+
with the following header, where you need to fill in `_________`:
131+
132+
```
133+
public static bool UserFoundSecretWord(_________ string uInput){
134+
```
135+
136+
<details><summary>Solution</summary>
137+
```{download="./code/projects/UserFoundSecretWord.zip"}
138+
!include`snippetStart="// Beginning of solution.",snippetEnd="// End of solution."` code/projects/UserFoundSecretWord/UserFoundSecretWord/Program.cs
139+
```
140+
</details>
141+
123142
#. Write the `AddLog` method (header included) such that the following:
124143

125144
```{download="./code/projects/ReferenceMethods.zip"}

0 commit comments

Comments
 (0)