Конструктор должен устанавливать значение поля title согласно переданному ему параметру.
если я пишу туда String title у меня оверрайд становится красным (у класса Book ведь без параметра он) или я не поняла про какой параметр, подскажите plz
@Override
public String getTitle(здесь должен быть какой-то параметр?) {
return this.title;
}
и из-за этого getOutputByBookType не проходит тоже. package com.javarush.task.task15.task1504;
import java.util.LinkedList;
import java.util.List;
/*
ООП - книги
*/
public class Solution {
public static void main(String[] args) {
List<Book> books = new LinkedList<Book>();
books.add(new MarkTwainBook("Mark Twain"));
books.add(new AgathaChristieBook("Agatha Christie"));
System.out.println(books);
}
public static class MarkTwainBook extends Book {
String author;
String title="Tom Sawyer";
public MarkTwainBook(String author) {
super(author);
this.author = author; }
@Override
public MarkTwainBook getBook() {
return this;
}
@Override
public String getTitle() {
return this.title;
}
}
public static class AgathaChristieBook extends Book{
String author;
String title="Hercule Poirot";
public AgathaChristieBook(String author) {
super(author);
this.author = author; }
@Override
public AgathaChristieBook getBook() {
return this;
}
@Override
public String getTitle() {
return this.title;
}
}
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";
switch (author) {
case "Agatha Christie":
output = agathaChristieOutput;
break;
case "Mark Twain":
output = markTwainOutput;
break;
}
return output;
}
public String toString() {
return getOutputByBookType();
}
}
}