Advertisement
vkarakolev

objectsEx2

Feb 25th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E02_Articles {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String[] inputLine = scanner.nextLine().split(", ");
  7.         Article article = new Article(inputLine);
  8.         int commandCount = Integer.parseInt(scanner.nextLine());
  9.  
  10.         for (int i = 0; i < commandCount; i++) {
  11.             String[] command = scanner.nextLine().split(": ");
  12.  
  13.             switch (command[0]){
  14.                 case "Edit" :
  15.                     article.edit(command);
  16.                     break;
  17.                 case "ChangeAuthor" :
  18.                     article.changeAuthor(command);
  19.                     break;
  20.                 case "Rename" :
  21.                     article.rename(command);
  22.                     break;
  23.             }
  24.         }
  25.        
  26.         article.toString(article);
  27.     }
  28.    
  29.     static class Article {
  30.         String title;
  31.         String  content;
  32.         String author;
  33.  
  34.         public Article (String[] inputLine){
  35.             this.title = inputLine[0];
  36.             this.content = inputLine[1];
  37.             this.author = inputLine[2];
  38.         }
  39.  
  40.         public void edit (String[] command){
  41.             this.content = command[1];
  42.         }
  43.  
  44.         public void changeAuthor (String[] command){
  45.             this.author = command[1];
  46.         }
  47.  
  48.         public void rename (String[] command){
  49.             this.title = command[1];
  50.         }
  51.  
  52.         public void toString (Article article){
  53.             String output = String.format("%s - %s: %s", title, content, author);
  54.             System.out.println(output);
  55.         }
  56.     }
  57.    
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement