Java Advanced - Book Comparator 66/100
Здравейте,
На задача 4 от лекцията Iterators and Comparators от Java Advanced ми гърми един тест в Judge. Задачата е решена по същия начин и в презентацията и в лекцията, но не откривам проблема.
BookComparator class-a -> https://pastebin.com/PpPMDR7c
Book class-a -> https://pastebin.com/da20f2Vi
Main class-a -> https://pastebin.com/tzMgQgHF
Линк към задачата в Judge -> https://judge.softuni.org/Contests/Practice/Index/1542#3
Условието на задачата:
Create a class BookComparator from UML diagram below:
<<Comparator<Book>>> BookComparator |
|
+ |
compare(Book, Book): int |
BookComparator has to compare two books by:
- Book title
- Year of publishing a book
Examples
Main.java |
public static void main(String[] args) { Book bookOne = new Book("Animal Farm", 2003, "George Orwell"); Book bookThree = new Book("The Documents in the Case", 2002); Book bookTwo = new Book("The Documents in the Case", 1930, "Dorothy Sayers", "Robert Eustace"); List<Book> books = new ArrayList<>(); books.add(bookOne); books.add(bookTwo); books.add(bookThree); books.sort(new BookComparator()); for (Book : books) { System.out.println(book.getTitle() + book.getYear()); } } |