Advertisement
IrinaIgnatova

Articles

Jul 10th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.     static class Article {
  10.  
  11.         private String title;
  12.         private String content;
  13.         private String autor;
  14.  
  15.         public Article(String title, String content, String autor) {
  16.  
  17.             this.title = title;
  18.             this.content = content;
  19.             this.autor = autor;
  20.         }
  21.  
  22.         public String getTitle() {
  23.             return title;
  24.         }
  25.  
  26.         public void setTitle(String title) {
  27.             this.title = title;
  28.         }
  29.  
  30.         public String getContent() {
  31.             return content;
  32.         }
  33.  
  34.         public void setContent(String content) {
  35.             this.content = content;
  36.         }
  37.  
  38.         public String getAutor() {
  39.             return autor;
  40.         }
  41.  
  42.         public void setAutor(String autor) {
  43.             this.autor = autor;
  44.         }
  45.  
  46.         @Override
  47.         public String toString() {
  48.             return String.format("%s - %s: %s", getTitle(), getContent(), getAutor());
  49.         }
  50.     }
  51.  
  52.     public static void main(String[] args) {
  53.  
  54.         Scanner scanner = new Scanner(System.in);
  55.         String line = scanner.nextLine();
  56.         String[] tokens = line.split(", ");
  57.         String title = tokens[0];
  58.         String content = tokens[1];
  59.         String autor = tokens[2];
  60.  
  61.  
  62.         Article article = new Article(title, content, autor);
  63.  
  64.  
  65.         int n = Integer.parseInt(scanner.nextLine());
  66.  
  67.         for (int i = 0; i < n; i++) {
  68.             String command = scanner.nextLine();
  69.             if (command.contains("Edit")) {
  70.                 String[] input = command.split(": ");
  71.                 String newContent = input[1];
  72.                 article.setContent(newContent);
  73.  
  74.             } else if (command.contains("ChangeAuthor")) {
  75.                 String[] input = command.split(": ");
  76.                 String newAutor = input[1];
  77.                 article.setAutor(newAutor);
  78.             } else if (command.contains("Rename")) {
  79.                 String[] input = command.split(": ");
  80.                 String newTitle = input[1];
  81.                 article.setTitle(newTitle);
  82.             }
  83.  
  84.  
  85.         }
  86.         System.out.println(article);
  87.  
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement