Didart

Articles

Nov 1st, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Articles {
  4.  
  5.     private String title;
  6.     private String content;
  7.     private String author;
  8.  
  9.     public Articles(String title, String content, String author) {
  10.         this.title = title;
  11.         this.content = content;
  12.         this.author = author;
  13.     }
  14.  
  15.     public void setContent(String newContent) {
  16.         this.content = newContent;
  17.     }
  18.  
  19.     public void setAuthor(String newAuthor) {
  20.         this.author = newAuthor;
  21.     }
  22.  
  23.     public void setTitle(String newTitle) {
  24.         this.title = newTitle;
  25.     }
  26.  
  27.     @Override
  28.     public String toString() {
  29.  
  30.         return String.format("%s - %s: %s", this.title, this.content, this.author);
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.         Scanner scanner = new Scanner(System.in);
  35.  
  36.         String[] articlesParts = scanner.nextLine().split(", ");
  37.  
  38.         String title = articlesParts[0];
  39.         String content = articlesParts[1];
  40.         String author = articlesParts[2];
  41.  
  42.         Articles article = new Articles(title, content, author);
  43.  
  44.         int commandsCount = Integer.parseInt(scanner.nextLine());
  45.         for (int count = 1; count <= commandsCount; count++) {
  46.             String command = scanner.nextLine();
  47.  
  48.             String commandName = command.split(": ")[0];
  49.             String newValue = command.split(": ")[1];
  50.  
  51.             switch (commandName) {
  52.                 case "Edit":
  53.                     article.setContent(newValue);
  54.                     break;
  55.                 case "ChangeAuthor":
  56.                     article.setAuthor(newValue);
  57.                     break;
  58.                 case "Rename":
  59.                     article.setTitle(newValue);
  60.                     break;
  61.             }
  62.         }
  63.         System.out.println(article);
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment