I actually don't know what the task wants me to do. conainsBones was boolean originally and i thought switching it to String will return a string object with the value "Yes" and that would pass the tests. But it seems that even the requirement that the containsBones returns "Yes" is false even though the code works as intended. I don't know what to do anymore.
package de.codegym.task.task15.task1505;
import java.util.ArrayList;
import java.util.List;
/*
OOP: Vererbungsprobleme korrigieren
*/
public class Solution {
public static interface LivingPart {
String containsBones();
}
public static class BodyPart implements LivingPart {
private String name;
public BodyPart(String name) {
this.name = name;
}
public String containsBones() {
String s = new String();
s = "Ja";
return s;
}
public String toString() {
return containsBones().equals("Ja") ? name + " enthält Knochen" : name + " enthält keine Knochen";
}
}
public static class Finger extends BodyPart {
private boolean isArtificial;
public Finger(String name, boolean isArtificial) {
super(name);
this.isArtificial = isArtificial;
}
public String containsBones() {
String s = super.containsBones().equals("Ja") && !isArtificial ? "Ja" : "Nein";
return s;
}
}
public static void main(String[] args) {
printlnFingers();
printlnBodyParts();
printlnLivingParts();
}
private static void printlnLivingParts() {
System.out.println(new BodyPart("Hand").containsBones());
}
private static void printlnBodyParts() {
List<BodyPart> bodyParts = new ArrayList<BodyPart>(5);
bodyParts.add(new BodyPart("Hand"));
bodyParts.add(new BodyPart("Bein"));
bodyParts.add(new BodyPart("Kopf"));
bodyParts.add(new BodyPart("Körper"));
System.out.println(bodyParts.toString());
}
private static void printlnFingers() {
List<Finger> fingers = new ArrayList<Finger>(5);
fingers.add(new Finger("Daumen", true));
fingers.add(new Finger("Zeigefinger", true));
fingers.add(new Finger("Mittelfiinger", true));
fingers.add(new Finger("Ringfinger", false));
fingers.add(new Finger("Kleiner Finger", true));
System.out.println(fingers.toString());
}
}