Hello! It shows correctly result in IDE. Why CodeGym doesn't accept it?
package com.codegym.task.task15.task1504;
import java.util.LinkedList;
import java.util.List;
/*
OOP: Books
*/
public class Solution {
public static void main(String[] args) {
List<Book> books = new LinkedList<Book>();
books.add(new MarkTwainBook("Tom Sawyer"));
books.add(new AgathaChristieBook("Hercule Poirot"));
System.out.println(books);
}
public static class MarkTwainBook extends Book {
private String author;
public MarkTwainBook(String author) {
super("Mark Twain");
this.author = author;
}
@Override
public Book getBook() {
return this;
}
@Override
public String getTitle() {
return author;
}
}
public static class AgathaChristieBook extends Book{
private String author;
public AgathaChristieBook(String author) {
super("Agatha Christie");
this.author = author;
}
@Override
public Book getBook() {
return this;
}
@Override
public String getTitle() {
return author;
}
}
abstract static class Book {
private String author;
public Book(String author) {
this.author = author;
}
public abstract Book getBook();
public abstract String getTitle();
private String getOutputByBookType() {
String agathaChristieOutput = author + ": " + getBook().getTitle() + " is a detective";
String markTwainOutput = getBook().getTitle() + " was written by " + author;
String output = "output";
//write your code here
if (getBook() instanceof AgathaChristieBook) output = agathaChristieOutput;
else if (getBook() instanceof MarkTwainBook) output = markTwainOutput;
return output;
}
public String toString() {
return getOutputByBookType();
}
}
}