Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ObjectNClasses.Articles;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(", ");
- String title = input[0];
- String content = input[1];
- String author = input[2];
- Article article = new Article(title, content, author);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- input = scanner.nextLine().split(": ");
- String command = input[0];
- switch (command) {
- case "Edit":
- article.edit(input[1]);
- break;
- case "ChangeAuthor":
- article.changeAuthor(input[1]);
- break;
- case "Rename":
- article.rename(input[1]);
- break;
- }
- }
- System.out.println(article);
- }
- public static class Article {
- private String title;
- private String content;
- private String author;
- public Article(String title, String content, String author) {
- this.title = title;
- this.content = content;
- this.author = author;
- }
- public void edit(String content) {
- this.content = content;
- //Заменяме старият с новият.
- }
- public void changeAuthor(String author) {
- this.author = author;
- }
- public void rename(String title) {
- this.title = title;
- }
- @Override
- public String toString() {
- String result = String.format("%s - %s: %s",
- this.title, this.content, this.author);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement