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..e9970d82 --- /dev/null +++ b/20_Buzzword/csharp/Program.cs @@ -0,0 +1,115 @@ +using System; + +namespace Buzzword +{ + class Program + { + /// + /// Displays header. + /// + static void Header() + { + Console.WriteLine("Buzzword generator".PadLeft(26)); + Console.WriteLine("Creating Computing Morristown, New Jersey".PadLeft(15)); + Console.WriteLine(); + Console.WriteLine(); + 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" + + "and speeches. Whenever a question mark is printed,\n" + + $"{keys}."); + Console.WriteLine(); + Console.WriteLine(); + Console.Write("Here's the first phrase:"); + } + + static string[] Words = new[] + { "ability", "basal", "behavioral", "child-centered", + "differentiated", "discovery", "flexible", "heterogenous", + "homogeneous", "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" }; + + /// + /// Capitalizes first letter of given string. + /// + /// + /// string + static string Capitalize(string input) + { + if (string.IsNullOrWhiteSpace(input)) + return string.Empty; + + return char.ToUpper(input[0]) + input[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); + + /// + /// 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(Words[rnd.Next(13)])} " + + $"{Words[rnd.Next(13, 26)]} " + + $"{Words[rnd.Next(26, 39)]}"; + } + + /// + /// 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; + else if (answer.Key == ConsoleKey.N) + return false; + else + Console.WriteLine($"\n{keys}"); + } + } + + static void Main(string[] args) + { + Header(); + Instructions(); + + while (true) + { + Console.WriteLine(); + Console.WriteLine(GeneratePhrase()); + Console.WriteLine(); + + if (!Decision()) + break; + } + + Console.WriteLine("\nCome back when you need help with another report!"); + } + } +}