static void OpenProgram(string key) { if (key == "Basic") { DocumentProgram document1 = new DocumentProgram(); document1.OpenDocument(); document1.EditDocument(); document1.SaveDocument(); } else if (key == "Pro") { DocumentProgram document2 = new ProDocumentProgram(); document2.OpenDocument(); document2.EditDocument(); document2.SaveDocument(); } else if (key == "Expert") { DocumentProgram document3 = new ExpertDocumentProgram(); document3.OpenDocument(); document3.EditDocument(); document3.SaveDocument(); } else { Console.WriteLine("0"); } }
static void Main(string[] args) { try { string key; DocumentProgram program = null; do { Console.Write("Enter key: "); key = Console.ReadLine(); } while (String.IsNullOrEmpty(key)); if (key == ProgramKeys.Basic) { program = new DocumentProgram(); } else if (key == ProgramKeys.Pro) { program = new ProDocumentProgram(); } else if (key == ProgramKeys.Expert) { program = new ExpertDocument(); } else { throw new ProgramKeyException($"There is no key equal to -> {key}"); } program.OpenDocument(); program.EditDocument(); program.SaveDocument(); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(e.Message); Console.ResetColor(); } }