Advertisement
dragonbs

Articles

Mar 5th, 2023
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Article
  6. {
  7.     public string Title { get; set; }
  8.  
  9.     public string Content { get; set; }
  10.  
  11.     public string Author { get; set; }
  12.  
  13.     public void Edit(string newContent)
  14.     {
  15.         Content = newContent;
  16.     }
  17.  
  18.     public void ChangeAuthor(string newAuthor)
  19.     {
  20.         Author = newAuthor;
  21.     }
  22.  
  23.     public void Rename(string newTitle)
  24.     {
  25.         Title = newTitle;
  26.     }
  27.  
  28.     public override string ToString()
  29.     {
  30.         return $"{Title} - {Content}: {Author}";
  31.     }
  32.  
  33.     public Article(string title, string content, string author)
  34.     {
  35.         Title = title;
  36.         Content = content;
  37.         Author = author;
  38.     }
  39. }
  40.  
  41. internal class Program
  42. {
  43.     static void Main()
  44.     {
  45.         string[] articleInfo = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None);
  46.         Article articleObject = new Article(articleInfo[0], articleInfo[1], articleInfo[2]);
  47.         int commands = int.Parse(Console.ReadLine());
  48.         for (int i = 0; i < commands; i++)
  49.         {
  50.             string[] input = Console.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None);
  51.             switch (input[0])
  52.             {
  53.                 case "Edit": articleObject.Edit(input[1]); break;
  54.                 case "ChangeAuthor": articleObject.ChangeAuthor(input[1]); break;
  55.                 case "Rename": articleObject.Rename(input[1]); break;
  56.             }
  57.         }
  58.         Console.WriteLine(articleObject.ToString());
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement