I just don't understand at all what these lines are asking from me;
3. The MarkTwainBook class must correctly implement a constructor with one String parameter (book title).
and
8. The AgathaChristieBook class must correctly implement a constructor with one String parameter (book title).
Also, from what I can tell the getTitle() should be working perfectly fine.
and what is a String field title?
I am beyond frustrated with this one at this point and could really use some deep explanation and even some theory as to why I struggling with all this at this point. It's starting to feel like I am not getting anything this forsaken website is trying to teach. Did anyone else feel this way?
package com.codegym.task.task15.task1504;
import java.awt.*;
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 bookTitle;
public MarkTwainBook(String bookTitle) {
super("Mark Twain");
this.bookTitle = bookTitle;
}
@Override
public MarkTwainBook getBook() {
return MarkTwainBook.this;
}
@Override
public String getTitle() {
return bookTitle;
}
}
public static class AgathaChristieBook extends Book {
private String bookTitle;
public AgathaChristieBook(String bookTitle) {
super("Agatha Christie");
this.bookTitle = bookTitle;
}
@Override
public AgathaChristieBook getBook() {
return AgathaChristieBook.this;
}
@Override
public String getTitle() {
return bookTitle;
}
}
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";
if (this instanceof MarkTwainBook) {
output = markTwainOutput;
}
else if (this instanceof AgathaChristieBook) {
output = agathaChristieOutput;
}
return output;
}
public String toString() {
return getOutputByBookType();
}
}
}