Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static class Article {
- private String getTitle () {
- return title;
- }
- private String getContent () {
- return content;
- }
- private String getAuthor () {
- return author;
- }
- String title;
- String content;
- String author;
- public Article (String title, String content,String author ) {
- this.title=title;
- this.author= author;
- this.content=content;
- }
- @Override
- public String toString() {
- return String.format ("%s - %s: %s%n", this.title, this.content, this.author);
- }
- }
- public static void main(String[] args) {
- Scanner sc= new Scanner(System.in);
- List<Article> articles = new ArrayList<>();
- int numberCommannds = Integer.parseInt(sc.nextLine());
- for (int i = 0; i < numberCommannds ; i++) {
- String[] tokens = sc.nextLine().split(", ");
- String title = tokens[0];
- String content = tokens[1];
- String author = tokens[2];
- Article article = new Article(title, content, author);
- articles.add(article);
- }
- String command = sc.nextLine();
- if (command.equals("title")) {
- articles.sort(Comparator.comparing(Article::getTitle));
- System.out.println(articles.toString().replaceAll("[\\[\\],]", ""));
- } else if (command.equals("content")) {
- articles.sort(Comparator.comparing(Article::getContent));
- System.out.println(articles.toString().replaceAll("[\\[\\],]", ""));
- } else if (command.equals("author")) {
- articles.sort(Comparator.comparing(Article::getAuthor));
- System.out.println(articles.toString().replaceAll("[\\[\\],]", ""));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement