SHARE
TWEET

02. Articles

a guest Dec 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     static class Article {
  8.         private String title;
  9.         private String content;
  10.         private String author;
  11.         public Article (String title, String content,String author ) {
  12.             this.title=title;
  13.             this.author= author;
  14.             this.content=content;
  15.         }
  16.        public void edit (String newContent)
  17.        {
  18.            this.content=newContent;
  19.        }
  20.  
  21.        public void changeAuthor (String newauthor)
  22.        {
  23.            this.author= newauthor;
  24.        }
  25.         public void renameArticle (String newName)
  26.         {
  27.             this.title= newName;
  28.         }
  29.  
  30.         @Override
  31.         public String toString() {
  32.             return String.format ("%s - %s: %s", this.title, this.content, this.author);
  33.         }
  34.     }
  35.  
  36.  
  37.  
  38.     public static void main(String[] args) {
  39.         Scanner sc= new Scanner(System.in);
  40.         String [] inputData= sc.nextLine().split(", ");
  41.  
  42.         Article article = new Article (inputData[0], inputData[1], inputData[2]);
  43.         int numberCommannds = Integer.parseInt(sc.nextLine());
  44.         while (numberCommannds>0)
  45.         {
  46.             String [] tokens = sc.nextLine().split(": ");
  47.             String command= tokens[0];
  48.             if (command.equals(("Edit")))
  49.             {
  50.                 article.edit(tokens[1]);
  51.  
  52.             }
  53.             else if (command.equals("ChangeAuthor")) {
  54.                 article.changeAuthor(tokens[1]);
  55.  
  56.             }
  57.             else {
  58.                 article.renameArticle(tokens[1]);
  59.  
  60.             }
  61.  
  62.             numberCommannds--;
  63.  
  64.  
  65.         }
  66.         System.out.println(article.toString());
  67.  
  68.  
  69.  
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top