Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10.ObjectsAndClasses-Articles
- Create a class Article with the following properties:
- • Title – a string
- • Content – a string
- • Author – a string
- The class should have a constructor and the following methods:
- • Edit (new content) – change the old content with the new one
- • ChangeAuthor (new author) – change the author
- • Rename (new title) – change the title of the article
- • Override the ToString method – print the article in the following format:
- "{title} - {content}: {autor}"
- Write a program that reads an article in the following format "{title}, {content}, {author}". On the next line, you will receive a number n, representing the number of commands, which will follow after it. On the next n lines, you will be receiving the following commands: "Edit: {new content}"; "ChangeAuthor: {new author}"; "Rename: {new title}". At the end, print the final state of the article.
- Example
- Input Output
- some title, some content, some author better title - better content: better author
- 3
- Edit: better content
- ChangeAuthor: better author
- Rename: better title
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LecturePractice
- {
- public class Program
- {
- public static void Main()
- {
- var inputText = Console.ReadLine().Split(", ").ToList();
- var number = int.Parse(Console.ReadLine());
- for (int i = 0; i < number; i++)
- {
- var newInputText = Console.ReadLine().Split(':').Select(s => s.Trim()).ToList();
- //Чрез метода Trim() се премахва ненужния спейс, който е останал след сплитването!
- if (newInputText[0] == "Edit")
- {
- inputText[1] = newInputText[1];
- }
- else if (newInputText[0] == "ChangeAuthor")
- {
- inputText[2] = newInputText[1];
- }
- else if (newInputText[0] == "Rename")
- {
- inputText[0] = newInputText[1];
- }
- }
- Console.WriteLine($"{inputText[0]} - {inputText[1]}: {inputText[2]}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment