StoimenK

C#_Objects_and_Classes_1.2.Articles

Feb 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _1._2.Articles
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             string[] input = Console.ReadLine().Split(',');
  10.             Article myArticle = new Article(input[0], input[1], input[2]);
  11.  
  12.             int count = int.Parse(Console.ReadLine());
  13.             for (int i = 0; i < count; i++)
  14.             {
  15.                 string[] commandToken = Console.ReadLine().Split(':');
  16.                 string command = commandToken[0];
  17.  
  18.                 if (command == "Edit")
  19.                 {
  20.                     myArticle.Edit(commandToken[1]);
  21.                 }
  22.                 else if (command == "ChangeAuthor")
  23.                 {
  24.                     myArticle.ChangeAuthor(commandToken[1]);
  25.                 }
  26.                 else
  27.                 {
  28.                     myArticle.Rename(commandToken[1]);
  29.                 }
  30.             }
  31.             Console.WriteLine(myArticle);
  32.         }
  33.  
  34.         class Article
  35.         {
  36.             public Article(string title, string content, string author)
  37.             {
  38.                 this.Title = title;
  39.                 this.Content = content;
  40.                 this.Author = author;
  41.             }
  42.             public string Title { get; set; }
  43.             public string Content { get; set; }
  44.             public string Author { get; set; }
  45.  
  46.             public void Edit(string content)
  47.             {
  48.                 this.Content = content;
  49.             }
  50.  
  51.             public void ChangeAuthor(string author)
  52.             {
  53.                 this.Author = author;
  54.             }
  55.  
  56.             public void Rename(string title)
  57.             {
  58.                 this.Title = title;
  59.             }
  60.  
  61.             public override string ToString()
  62.             {
  63.                 return $"{this.Title} - {this.Content}: {this.Author}";
  64.             }
  65.  
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment