Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. // class Article { //когато е извън Main рябва да пише само class, без public static
  6.  
  7. // }
  8.  
  9. public class Articles {
  10.  
  11. public static class Article {
  12. private String title;
  13. private String content;
  14. private String author;
  15.  
  16. public Article(String title, String content, String author) {
  17. this.title = title;
  18. this.content = content;
  19. this.author = author;
  20. }
  21.  
  22. public void setContent(String content) {
  23. this.content = content;
  24. }
  25.  
  26. public void setAuthor(String author) {
  27. this.author = author;
  28. }
  29.  
  30. public void rename(String title) {
  31. this.title = title;
  32. }
  33.  
  34. @Override
  35. public String toString() { // to + Tab
  36. return String.format("%s - %s: %s", this.title, this.content, this.author);
  37. }
  38. }
  39.  
  40. public static void main(String[] args) {
  41. Scanner scanner = new Scanner(System.in);
  42.  
  43. String[] input = scanner.nextLine().split(", ");
  44.  
  45. String title = input[0];
  46. String content = input[1];
  47. String author = input[2];
  48.  
  49. Article article = new Article(title, content, author); //конструктор, създаваме нов обект
  50.  
  51. int n = Integer.parseInt(scanner.nextLine());
  52.  
  53. while (n-- > 0) {
  54. String[] tokens = scanner.nextLine().split(": ");
  55.  
  56. String command = tokens[0];
  57. String param = tokens[1];
  58.  
  59. if (command.equals("Edit")) {
  60. article.setContent(param);
  61. } else if (command.equals("ChangeAuthor")) {
  62. article.setAuthor(param);
  63. } else {
  64. article.rename(param);
  65. }
  66.  
  67. }
  68.  
  69. System.out.println(article);
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement