static void Main() { Console.WriteLine("Введите ключ"); string key = Console.ReadLine(); DocumentWorker doc = null; switch (key) { case "prof": doc = new ProDocumentWorker(); break; case "expert": doc = new ExpertDocumentWorker(); break; default: Console.WriteLine("Ключ неверен"); doc = new DocumentWorker(); break; } doc.OpenDocument(); doc.EditDocument(); doc.SaveDocument(); Console.ReadKey(); }
static void Main() { Console.WriteLine("Введите ключ"); string key = Console.ReadLine(); DocumentWorker doc = null; //Создание екземпляра класса DocumentWorker switch (key) { case "prof": doc = new ProDocumentWorker(); //Приведение экземпляра производного класса к базовому типу UpCast. break; case "expert": doc = new ExpertDocumentWorker(); break; default: Console.WriteLine("Ключ неверен"); doc = new DocumentWorker(); break; } doc.OpenDocument(); //вызов метода OpenDocument на экземпляре doc класса doc.EditDocument(); doc.SaveDocument(); Console.ReadKey(); }
static void Main(string[] args) { DocumentWorker doc = null; while (doc == null) { Console.WriteLine("Enter the KEY!('pro'/'exp')"); string line = Console.ReadLine(); if (line == "pro") { doc = new ProDocumentWorker(); } else if (line == "exp") { doc = new ExpertDocumentWorker(); } else { doc = new DocumentWorker(); } } doc.OpenDocument(); doc.EditDocument(); doc.SaveDocument(); }
static void WorkWithDocument(DocumentWorker document, string objectName) { Console.WriteLine(new string('.', 10)); Console.WriteLine("------- {0} ------", objectName); document.OpenDocument(); document.EditDocument(); document.SaveDocument(); }
static void Main(string[] args) { Console.WriteLine("[keys: pro, exp]"); Console.Write("Введите ключ PRO: "); string pro = Console.ReadLine(); Console.Write("Введите ключ EXPERT: "); string expert = Console.ReadLine(); DocumentWorker document = CreateDocumentWorker(pro, expert); Console.WriteLine("open: "); document.OpenDocument(); Console.WriteLine("edit: "); document.EditDocument(); Console.WriteLine("save: "); document.SaveDocument(); Console.ReadKey(); }
/* * Задание 4 * Используя Visual Studio, создайте проект по шаблону Console Application. * Требуется: * Создайте класс DocumentWorker. * В теле класса создайте три метода OpenDocument(), EditDocument(), SaveDocument(). * В тело каждого из методов добавьте вывод на экран соответствующих строк: "Документ открыт", * "Редактирование документа доступно в версии Про", "Сохранение документа доступно в * версии Про". * Создайте производный класс ProDocumentWorker. * Переопределите соответствующие методы, при переопределении методов выводите следующие строки: * "Документ отредактирован", "Документ сохранен в старом формате, сохранение в остальных * форматах доступно в версии Эксперт". * Создайте производный класс ExpertDocumentWorker от базового класса ProDocumentWorker. * Переопределите соответствующий метод. При вызове данного метода необходимо выводить на экран * "Документ сохранен в новом формате". * В теле метода Main() реализуйте возможность приема от пользователя номера ключа доступа pro и exp. * Если пользователь не вводит ключ, он может пользоваться только бесплатной версией (создается * экземпляр базового класса), если пользователь ввел номера ключа доступа pro и exp, то должен * создаться экземпляр соответствующей версии класса, приведенный к базовому - DocumentWorker. */ static void Main(string[] args) { DocumentWorker document = null; int i = 0; Random random = new Random(); while ((i++) != 4) { switch (random.Next(1, 4)) { case 1: { document = new DocumentWorker(); WorkWithDocument(document, "DocumentWorker"); break; } case 2: { document = new ExpertDocumentWorker(); WorkWithDocument(document, "ExpertDocumentWorker"); break; } case 3: { document = new ProDocumentWorker(); WorkWithDocument(document, "ProDocumentWorker"); break; } } } Console.ReadKey(); }
static void Main(string[] args) { DocumentWorker document = null; int key = new Random().Next(0, 1000); Console.WriteLine(key); if (key <= 300) { document = new DocumentWorker(); } if (key > 300 & key <= 650) { document = new ProDocumentWorker(); } if (key > 650 & key <= 1000) { document = new ExpertDocumentWorker(); } document.Show(); Console.ReadKey(); }
static void Main(string[] args) { string key; int choice; bool flag = true; Console.WriteLine("Введите ключ (если не имеете ключа просто нажмите Enter):"); key = Console.ReadLine(); switch (key) { case "": DocumentWorker documentLite = new DocumentWorker(); Console.WriteLine("Добро пожаловать в Lite версию!"); Menu(); while (flag) { choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: documentLite.OpenDocument(); break; case 2: documentLite.EditDocument(); break; case 3: documentLite.SaveDocument(); break; case 4: flag = false; break; } } break; case "pro": DocumentWorker documentPro = new ProDocumentWorker(); Console.WriteLine("Добро пожаловать в Pro версию!"); Menu(); while (flag) { choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: documentPro.OpenDocument(); break; case 2: documentPro.EditDocument(); break; case 3: documentPro.SaveDocument(); break; case 4: flag = false; break; } } break; case "exp": DocumentWorker documentExp = new ExpertDocumentWorker(); Console.WriteLine("Добро пожаловать в Expert версию!"); Menu(); while (flag) { choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: documentExp.OpenDocument(); break; case 2: documentExp.EditDocument(); break; case 3: documentExp.SaveDocument(); break; case 4: flag = false; break; } } break; default: Console.WriteLine("Неверный ввод!"); break; } Console.ReadKey(); }