Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Articles;
- import java.util.Scanner;
- public class Articles {
- public static class Article {
- String title;
- String content;
- String author;
- public Article(String title, String content, String author) {
- this.title = title;
- this.content = content;
- this.author = author;
- }
- public String detail(String[] changeDetails){
- String detail = "";
- for (int i = 1; i < changeDetails.length; i++) {
- detail += changeDetails[i]+" ";
- }
- return detail.trim();
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getContent() {
- return content;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public String getAuthor() {
- return author;
- }
- public void setAuthor(String author) {
- this.author = author;
- }
- public void printMessage(){
- String title = this.title;
- String author = this.author;
- String content = this.content;
- System.out.printf("%s - %s: %s", title,content,author);
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] input = sc.nextLine().split(",\\s+");
- Article article = new Article(input[0], input[1], input[2]){};
- int n = Integer.parseInt(sc.nextLine());
- for (int i = 0; i < n; i++) {
- String[] changeDetails = sc.nextLine().split("\\s+");
- String detail = article.detail(changeDetails);
- switch (changeDetails[0]) {
- case "Rename:":
- article.setTitle(detail);
- break;
- case "Edit:":
- article.setContent(detail);
- break;
- case "ChangeAuthor:":
- article.setAuthor(detail);
- break;
- }
- }
- article.printMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement