Created
March 19, 2017 12:54
-
-
Save fermopili/8ca8d54622727bfa850ab165d1cf236c to your computer and use it in GitHub Desktop.
com.javarush.task.task15.task1505
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ООП - исправь ошибки в наследовании | |
*/ | |
public class Solution { | |
public static interface Alive { | |
Object containsBones(); | |
} | |
public static class BodyPart implements Alive { | |
private String name; | |
public BodyPart(String name) { | |
this.name = name; | |
} | |
public Object containsBones() { | |
return "Yes"; | |
} | |
public String toString() { | |
if( containsBones().equals("Yes")) return name + " содержит кости"; | |
return name + " не содержит кости"; | |
} | |
} | |
public static class Finger extends BodyPart { | |
private boolean isArtificial; | |
public Finger(String name, boolean isArtificial) { | |
super(name); | |
this.isArtificial = isArtificial; | |
} | |
public Object containsBones() { | |
if((super.containsBones().equals("Yes"))&& !isArtificial) return "Yes"; | |
return "No"; | |
} | |
} | |
public static void main(String[] args) { | |
printlnFingers(); | |
printlnBodyParts(); | |
printlnAlives(); | |
} | |
private static void printlnAlives() { | |
System.out.println(new BodyPart("Рука").containsBones()); | |
} | |
private static void printlnBodyParts() { | |
List<BodyPart> bodyParts = new ArrayList<BodyPart>(5); | |
bodyParts.add(new BodyPart("Рука")); | |
bodyParts.add(new BodyPart("Нога")); | |
bodyParts.add(new BodyPart("Голова")); | |
bodyParts.add(new BodyPart("Тело")); | |
System.out.println(bodyParts.toString()); | |
} | |
private static void printlnFingers() { | |
List<Finger> fingers = new ArrayList<Finger>(5); | |
fingers.add(new Finger("Большой", true)); | |
fingers.add(new Finger("Указательный", true)); | |
fingers.add(new Finger("Средний", true)); | |
fingers.add(new Finger("Безымянный", false)); | |
fingers.add(new Finger("Мизинец", true)); | |
System.out.println(fingers.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment