Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- static class Article {
- private String title;
- private String content;
- private String author;
- public Article (String title, String content,String author ) {
- this.title=title;
- this.author= author;
- this.content=content;
- }
- public void edit (String newContent)
- {
- this.content=newContent;
- }
- public void changeAuthor (String newauthor)
- {
- this.author= newauthor;
- }
- public void renameArticle (String newName)
- {
- this.title= newName;
- }
- @Override
- public String toString() {
- return String.format ("%s - %s: %s", this.title, this.content, this.author);
- }
- }
- public static void main(String[] args) {
- Scanner sc= new Scanner(System.in);
- String [] inputData= sc.nextLine().split(", ");
- Article article = new Article (inputData[0], inputData[1], inputData[2]);
- int numberCommannds = Integer.parseInt(sc.nextLine());
- while (numberCommannds>0)
- {
- String [] tokens = sc.nextLine().split(": ");
- String command= tokens[0];
- if (command.equals(("Edit")))
- {
- article.edit(tokens[1]);
- }
- else if (command.equals("ChangeAuthor")) {
- article.changeAuthor(tokens[1]);
- }
- else {
- article.renameArticle(tokens[1]);
- }
- numberCommannds--;
- }
- System.out.println(article.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement