From 7318b0b5d5185f61c7614e860dad7229c5cf0603 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 11:12:12 +0100 Subject: [PATCH 01/12] Added header --- 20_Buzzword/csharp/Buzzword.csproj | 8 ++++++++ 20_Buzzword/csharp/Buzzword.sln | 25 +++++++++++++++++++++++++ 20_Buzzword/csharp/Program.cs | 20 ++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 20_Buzzword/csharp/Buzzword.csproj create mode 100644 20_Buzzword/csharp/Buzzword.sln create mode 100644 20_Buzzword/csharp/Program.cs diff --git a/20_Buzzword/csharp/Buzzword.csproj b/20_Buzzword/csharp/Buzzword.csproj new file mode 100644 index 00000000..1d2d39a9 --- /dev/null +++ b/20_Buzzword/csharp/Buzzword.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/20_Buzzword/csharp/Buzzword.sln b/20_Buzzword/csharp/Buzzword.sln new file mode 100644 index 00000000..ada2d937 --- /dev/null +++ b/20_Buzzword/csharp/Buzzword.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.810.15 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Buzzword", "Buzzword.csproj", "{E342DEB2-F009-47FD-85F6-E84965EAAB56}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E342DEB2-F009-47FD-85F6-E84965EAAB56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E342DEB2-F009-47FD-85F6-E84965EAAB56}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E342DEB2-F009-47FD-85F6-E84965EAAB56}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E342DEB2-F009-47FD-85F6-E84965EAAB56}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {52F15A7F-671A-470D-91CE-F3B629B989B7} + EndGlobalSection +EndGlobal diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs new file mode 100644 index 00000000..5e5ea8ec --- /dev/null +++ b/20_Buzzword/csharp/Program.cs @@ -0,0 +1,20 @@ +using System; + +namespace Buzzword +{ + class Program + { + static void Header() + { + Console.WriteLine("Buzzword generator".PadLeft(26)); + Console.WriteLine("Creating Computing Morristown, New Jersey".PadLeft(15)); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine(); + } + static void Main(string[] args) + { + Header(); + } + } +} From 2a6dc209c8efc96ae84e31f45f89abecf0b74313 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 11:17:05 +0100 Subject: [PATCH 02/12] Added Instructions --- 20_Buzzword/csharp/Program.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index 5e5ea8ec..f8c04586 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -12,9 +12,22 @@ namespace Buzzword Console.WriteLine(); Console.WriteLine(); } + + static void Instructions() + { + Console.WriteLine("This program prints highly acceptable phrases in\n" + + "'Educator-speak'that you can work into reports\n" + + "and speeches. Whenever a question mark is printed,\n" + + "type a 'Y' for another phrase or 'N' to quit."); + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("Here's the first phrase:"); + } + static void Main(string[] args) { Header(); + Instructions(); } } } From ff67d7705ace820dc6336ce253548c0d44ae148c Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 11:59:28 +0100 Subject: [PATCH 03/12] Added GeneratePhrase --- 20_Buzzword/csharp/Program.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index f8c04586..1398d442 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -24,10 +24,41 @@ namespace Buzzword Console.WriteLine("Here's the first phrase:"); } + static string[] Phrases = new[] + { "ability", "basal", "behavioral", "child-centered", + "differentiated", "discovery", "flexible", "heterogenous", + "homogenous", "manipulative", "modular", "tavistock", + "individualized", "learning", "evaluative", "objective", + "cognitive", "enrichment", "scheduling", "humanistic", + "integrated", "non-graded", "training", "vertical age", + "motivational", "creative", "grouping", "modification", + "accountability", "process", "core curriculum", "algorithm", + "performance", "reinforcement", "open classroom", "resource", + "structure", "facility", "environment" }; + + static Random rnd = new Random(1); + + static string GeneratePhrase() + { + return $"{Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length]} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}."; + } + static void Main(string[] args) { Header(); Instructions(); + + while (true) + { + Console.WriteLine(); + Console.WriteLine(GeneratePhrase()); + var answer = Console.ReadKey(); + + if (answer.Key == ConsoleKey.N) + break; + } } } } From 62645703d1d15ec40b9b6ebfffd31091165ee360 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 12:05:19 +0100 Subject: [PATCH 04/12] Starting sentence from capital letter --- 20_Buzzword/csharp/Program.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index 1398d442..dcfdcd38 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -36,11 +36,19 @@ namespace Buzzword "performance", "reinforcement", "open classroom", "resource", "structure", "facility", "environment" }; + static string Capitalize(string input) + { + if (string.IsNullOrWhiteSpace(input)) + return string.Empty; + + return input.Substring(0, 1).ToUpper() + input[1..]; + } + static Random rnd = new Random(1); static string GeneratePhrase() { - return $"{Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length]} " + return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length])} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}."; } @@ -54,8 +62,8 @@ namespace Buzzword { Console.WriteLine(); Console.WriteLine(GeneratePhrase()); - var answer = Console.ReadKey(); + var answer = Console.ReadKey(); if (answer.Key == ConsoleKey.N) break; } From e9cc632c7b0b884783218d6950820c3b8efbe32f Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 12:15:13 +0100 Subject: [PATCH 05/12] Better keyboard, cosmetics --- 20_Buzzword/csharp/Program.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index dcfdcd38..3506cc5e 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -13,15 +13,17 @@ namespace Buzzword Console.WriteLine(); } + static string keys = "type a 'Y' for another phrase or 'N' to quit"; + static void Instructions() { Console.WriteLine("This program prints highly acceptable phrases in\n" + "'Educator-speak'that you can work into reports\n" + "and speeches. Whenever a question mark is printed,\n" - + "type a 'Y' for another phrase or 'N' to quit."); + + $"{keys}."); Console.WriteLine(); Console.WriteLine(); - Console.WriteLine("Here's the first phrase:"); + Console.Write("Here's the first phrase:"); } static string[] Phrases = new[] @@ -50,7 +52,21 @@ namespace Buzzword { return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length])} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}."; + + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}"; + } + + static bool Decision() + { + while (true) + { + var answer = Console.ReadKey(); + if (answer.Key == ConsoleKey.Y) + return true; + else if (answer.Key == ConsoleKey.N) + return false; + else + Console.WriteLine($"\n{keys}"); + } } static void Main(string[] args) @@ -62,11 +78,13 @@ namespace Buzzword { Console.WriteLine(); Console.WriteLine(GeneratePhrase()); + Console.WriteLine(); - var answer = Console.ReadKey(); - if (answer.Key == ConsoleKey.N) + if (!Decision()) break; } + + Console.WriteLine("\nCome back when you need help with another report!"); } } } From a1fd52ebfd5711575c445086b7c066cc889ee550 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 13:16:01 +0100 Subject: [PATCH 06/12] Modified seed, added some comments --- 20_Buzzword/csharp/Program.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index 3506cc5e..ec07d18d 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -46,13 +46,17 @@ namespace Buzzword return input.Substring(0, 1).ToUpper() + input[1..]; } - static Random rnd = new Random(1); + // Seed has been calculated to get the same effect as in original, + // at least in first phrase + static readonly Random rnd = new Random(1486); static string GeneratePhrase() { - return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length])} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}"; + // Indexing from 0, so had to decrease generated numbers + // modulo Phrases.Length added to not get out of bond + return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble()) % Phrases.Length])} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 13) % Phrases.Length]} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 26) % Phrases.Length]}"; } static bool Decision() From cf659356152ef6c3111734844dbaf93962b46aa6 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 13:17:35 +0100 Subject: [PATCH 07/12] After modifying indexes modulo isn't needed, it appears --- 20_Buzzword/csharp/Program.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index ec07d18d..d4311141 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -53,10 +53,9 @@ namespace Buzzword static string GeneratePhrase() { // Indexing from 0, so had to decrease generated numbers - // modulo Phrases.Length added to not get out of bond - return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble()) % Phrases.Length])} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 13) % Phrases.Length]} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 26) % Phrases.Length]}"; + return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble())])} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 13)]} " + + $"{Phrases[(int)(13 * rnd.NextDouble() + 26)]}"; } static bool Decision() From aceddf559e6b8dad41528c2408a73e76b06d19c8 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 13:28:38 +0100 Subject: [PATCH 08/12] Added more comments, some cosmetic changes --- 20_Buzzword/csharp/Program.cs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index d4311141..db72de7a 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -4,6 +4,9 @@ namespace Buzzword { class Program { + /// + /// Displays header. + /// static void Header() { Console.WriteLine("Buzzword generator".PadLeft(26)); @@ -13,12 +16,16 @@ namespace Buzzword Console.WriteLine(); } + // Information for the user about possible key input. static string keys = "type a 'Y' for another phrase or 'N' to quit"; + /// + /// Displays instructions. + /// static void Instructions() { Console.WriteLine("This program prints highly acceptable phrases in\n" - + "'Educator-speak'that you can work into reports\n" + + "'educator-speak' that you can work into reports\n" + "and speeches. Whenever a question mark is printed,\n" + $"{keys}."); Console.WriteLine(); @@ -26,7 +33,7 @@ namespace Buzzword Console.Write("Here's the first phrase:"); } - static string[] Phrases = new[] + static string[] Words = new[] { "ability", "basal", "behavioral", "child-centered", "differentiated", "discovery", "flexible", "heterogenous", "homogenous", "manipulative", "modular", "tavistock", @@ -38,6 +45,11 @@ namespace Buzzword "performance", "reinforcement", "open classroom", "resource", "structure", "facility", "environment" }; + /// + /// Capitalizes first letter of given string. + /// + /// + /// string static string Capitalize(string input) { if (string.IsNullOrWhiteSpace(input)) @@ -50,18 +62,29 @@ namespace Buzzword // at least in first phrase static readonly Random rnd = new Random(1486); + /// + /// Generates random phrase from words available in Words array. + /// + /// String representing random phrase where first letter is capitalized. static string GeneratePhrase() { // Indexing from 0, so had to decrease generated numbers - return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble())])} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 13)]} " - + $"{Phrases[(int)(13 * rnd.NextDouble() + 26)]}"; + // modulo Phrases.Length added to not get out of bond + return $"{Capitalize(Words[(int)(13 * rnd.NextDouble())])} " + + $"{Words[(int)(13 * rnd.NextDouble() + 13)]} " + + $"{Words[(int)(13 * rnd.NextDouble() + 26)]}"; } + /// + /// Handles user input. On wrong input it displays information about + /// valid keys in infinite loop. + /// + /// True if user pressed 'Y', false if 'N'. static bool Decision() { while (true) { + Console.Write("?"); var answer = Console.ReadKey(); if (answer.Key == ConsoleKey.Y) return true; From e23e9f6a9a5c5900cec099e1fdb2e1dc0c4315b2 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 13:39:03 +0100 Subject: [PATCH 09/12] Spelling --- 20_Buzzword/csharp/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index db72de7a..d940e534 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -36,7 +36,7 @@ namespace Buzzword static string[] Words = new[] { "ability", "basal", "behavioral", "child-centered", "differentiated", "discovery", "flexible", "heterogenous", - "homogenous", "manipulative", "modular", "tavistock", + "homogeneous", "manipulative", "modular", "tavistock", "individualized", "learning", "evaluative", "objective", "cognitive", "enrichment", "scheduling", "humanistic", "integrated", "non-graded", "training", "vertical age", From b1242d081cae763f2863d1e66eea549770024ca3 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 14:14:31 +0100 Subject: [PATCH 10/12] Better? --- 20_Buzzword/csharp/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index d940e534..b2dfa680 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -55,7 +55,7 @@ namespace Buzzword if (string.IsNullOrWhiteSpace(input)) return string.Empty; - return input.Substring(0, 1).ToUpper() + input[1..]; + return char.ToUpper(input[0]) + input[1..]; } // Seed has been calculated to get the same effect as in original, From 8cf778cb8706b835f7b70a364da2302adfe8bc4d Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 14:18:25 +0100 Subject: [PATCH 11/12] Comment changed --- 20_Buzzword/csharp/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index b2dfa680..ca1ed750 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -69,7 +69,7 @@ namespace Buzzword static string GeneratePhrase() { // Indexing from 0, so had to decrease generated numbers - // modulo Phrases.Length added to not get out of bond + // NextDouble used to reflect original return $"{Capitalize(Words[(int)(13 * rnd.NextDouble())])} " + $"{Words[(int)(13 * rnd.NextDouble() + 13)]} " + $"{Words[(int)(13 * rnd.NextDouble() + 26)]}"; From 520efaa20a44a3415a71a8dfb4c97e1c4a6cf0d3 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 17:12:13 +0100 Subject: [PATCH 12/12] Maybe staying too close to original wasn't so good --- 20_Buzzword/csharp/Program.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index ca1ed750..e9970d82 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -69,10 +69,9 @@ namespace Buzzword static string GeneratePhrase() { // Indexing from 0, so had to decrease generated numbers - // NextDouble used to reflect original - return $"{Capitalize(Words[(int)(13 * rnd.NextDouble())])} " - + $"{Words[(int)(13 * rnd.NextDouble() + 13)]} " - + $"{Words[(int)(13 * rnd.NextDouble() + 26)]}"; + return $"{Capitalize(Words[rnd.Next(13)])} " + + $"{Words[rnd.Next(13, 26)]} " + + $"{Words[rnd.Next(26, 39)]}"; } ///