Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exercise;
- import java.util.Scanner;
- public class Articles {
- static class Article {
- private String title;
- private String content;
- private String author;
- public String getTitle() {
- return title;
- }
- public String getContent() {
- return content;
- }
- public String getAuthor() {
- return author;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public void setAuthor(String author) {
- this.author = author;
- }
- public Article(String title, String content, String author) {
- this.title = title;
- this.content = content;
- this.author = author;
- }
- @Override
- public String toString() {
- return String.format("%s - %s: %s", title, content, author);
- }
- }
- 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++) {
- String[] commandInput = scanner.nextLine().split(":");
- String command = commandInput[0];
- String change = commandInput[1].trim();
- if (command.equals("Edit")) {
- article.setContent(change);
- } else if (command.equals("ChangeAuthor")) {
- article.setAuthor(change);
- } else if (command.equals("Rename")) {
- article.setTitle(change);
- }
- }
- System.out.println(article);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement