Advertisement
ShSh99

Article

Nov 12th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.Scanner;
  3.  
  4. class Article{
  5.     private  String title;
  6.     private  String content;
  7.     private  String author;
  8.  
  9.     public Article(String title, String content, String author) {
  10.         this.title = title;
  11.         this.content = content;
  12.         this.author = author;
  13.     }
  14.  
  15.     public void editContent (String newContent){
  16.         this.content = newContent;
  17.     }
  18.     public void changedAuthor(String newAuthor){
  19.         this.author = newAuthor;
  20.     }
  21.     public void renameTitle(String newTitle){
  22.         this.title = newTitle;
  23.     }
  24.  
  25.     public String getTitle() {
  26.         return title;
  27.     }
  28.  
  29.     public void setTitle(String title) {
  30.         this.title = title;
  31.     }
  32.  
  33.     public String getContent() {
  34.         return content;
  35.     }
  36.  
  37.     public void setContent(String content) {
  38.         this.content = content;
  39.     }
  40.  
  41.     public String getAuthor() {
  42.         return author;
  43.     }
  44.  
  45.     public void setAuthor(String author) {
  46.         this.author = author;
  47.     }
  48.  
  49.     @Override
  50.     public String toString() {
  51.         return String.format("%s - %s: %s",this.title, this.content, this.author);
  52.     }
  53.  
  54.  
  55.     public static void main(String[] args) {
  56.         Scanner sc = new Scanner(System.in);
  57.  
  58.         String[] data = sc.nextLine().split(", ");
  59.  
  60.         Article article = new Article(data[0], data[1],data[2]);
  61.  
  62.         int n = Integer.parseInt(sc.nextLine());
  63.  
  64.         while (n-- >0){
  65.             String[] tokens = sc.nextLine().split(": ");
  66.             String command = tokens[0];
  67.             if(command.equals("Edit")){
  68.                 article.editContent(tokens[1]);
  69.             }else if(command.equals("ChangeAuthor")){
  70.                 article.changedAuthor(tokens[1]);
  71.             }else {
  72.                 article.renameTitle(tokens[1]);
  73.             }
  74.         }
  75.         System.out.println(article.toString());
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement