Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.Scanner;
- 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 editContent (String newContent){
- this.content = newContent;
- }
- public void changedAuthor(String newAuthor){
- this.author = newAuthor;
- }
- public void renameTitle(String newTitle){
- this.title = newTitle;
- }
- 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;
- }
- @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[] data = sc.nextLine().split(", ");
- Article article = new Article(data[0], data[1],data[2]);
- int n = Integer.parseInt(sc.nextLine());
- while (n-- >0){
- String[] tokens = sc.nextLine().split(": ");
- String command = tokens[0];
- if(command.equals("Edit")){
- article.editContent(tokens[1]);
- }else if(command.equals("ChangeAuthor")){
- article.changedAuthor(tokens[1]);
- }else {
- article.renameTitle(tokens[1]);
- }
- }
- System.out.println(article.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement