Advertisement
Guest User

Articles

a guest
Feb 28th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package Articles;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Articles {
  6.  
  7.     public static class Article {
  8.  
  9.         String title;
  10.         String content;
  11.         String author;
  12.  
  13.         public Article(String title, String content, String author) {
  14.             this.title = title;
  15.             this.content = content;
  16.             this.author = author;
  17.         }
  18.  
  19.  
  20.         public String detail(String[] changeDetails){
  21.             String detail = "";
  22.             for (int i = 1; i < changeDetails.length; i++) {
  23.                 detail += changeDetails[i]+" ";
  24.             }
  25.             return detail.trim();
  26.         }
  27.  
  28.         public String getTitle() {
  29.             return title;
  30.         }
  31.  
  32.         public void setTitle(String title) {
  33.             this.title = title;
  34.         }
  35.  
  36.         public String getContent() {
  37.             return content;
  38.         }
  39.  
  40.         public void setContent(String content) {
  41.             this.content = content;
  42.         }
  43.  
  44.         public String getAuthor() {
  45.             return author;
  46.         }
  47.  
  48.         public void setAuthor(String author) {
  49.             this.author = author;
  50.         }
  51.  
  52.         public void printMessage(){
  53.             String title = this.title;
  54.             String author = this.author;
  55.             String content = this.content;
  56.             System.out.printf("%s - %s: %s", title,content,author);
  57.         }
  58.     }
  59.  
  60.     public static void main(String[] args) {
  61.         Scanner sc = new Scanner(System.in);
  62.         String[] input = sc.nextLine().split(",\\s+");
  63.         Article article = new Article(input[0], input[1], input[2]){};
  64.  
  65.         int n = Integer.parseInt(sc.nextLine());
  66.         for (int i = 0; i < n; i++) {
  67.             String[] changeDetails = sc.nextLine().split("\\s+");
  68.             String detail = article.detail(changeDetails);
  69.             switch (changeDetails[0]) {
  70.                 case "Rename:":
  71.                     article.setTitle(detail);
  72.                     break;
  73.                 case "Edit:":
  74.                     article.setContent(detail);
  75.                     break;
  76.                 case "ChangeAuthor:":
  77.                     article.setAuthor(detail);
  78.                     break;
  79.             }
  80.         }
  81.         article.printMessage();
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement