Code does not work because getBookByOutputType() returns the false string. But I have no idea how the correct string looks like.
package de.codegym.task.task15.task1504;
import java.util.LinkedList;
import java.util.List;
/*
OOP: Bücher
*/
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);
}
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 output = "";
for(int i = 0; i < this.author.length(); i++) {
char currentChar = this.author.charAt(i);
if(i == 0)
output += Character.toLowerCase(currentChar);
else if(currentChar == ' ') {
output += Character.toUpperCase(this.author.charAt(i + 1));
i++;
}
else
output += currentChar;
}
output += "Output";
return output;
}
public String toString() {
return getOutputByBookType();
}
}
public static class MarkTwainBook extends Book {
private String title;
public MarkTwainBook(String title) {
super("Mark Twain");
this.title = title;
}
public MarkTwainBook getBook() {
return this;
}
public String getTitle() {
return this.title;
}
}
public static class AgathaChristieBook extends Book {
private String title;
public AgathaChristieBook(String title) {
super("Agatha Christie");
this.title = title;
}
public AgathaChristieBook getBook() {
return this;
}
public String getTitle() {
return this.title;
}
}
/* private String getOutputByBookType() {
String agathaChristieOutput = author + ": " + getBook().getTitle() + " ist ein Privatdetektiv";
String markTwainOutput = getBook().getTitle() + " wurde geschrieben von " + author;
String output = "Ausgabe";
//schreib hier deinen Code
return output;
*/
}