package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String grandFatherName = reader.readLine();
Cat grandFather = new Cat(grandFatherName, null, null);
String grandMotherName = reader.readLine();
Cat grandMother = new Cat(grandMotherName, null, null);
String fatherName = reader.readLine();
Cat Father = new Cat(fatherName, null, grandFather);
String motherName = reader.readLine();
Cat Mother = new Cat(motherName, grandMother, null);
String sonName = reader.readLine();
Cat Son = new Cat(sonName, Mother, Father);
String daughterName = reader.readLine();
Cat Daughter = new Cat(daughterName, Mother, Father);
System.out.println(grandFather.toString());
System.out.println(grandMother.toString());
System.out.println(Father.toString());
System.out.println(Mother.toString());
System.out.println(Son.toString());
System.out.println(Daughter.toString());
}
public static class Cat {
private String name;
private Cat Father;
private Cat Mother;
Cat(String name, Cat Mother, Cat Father) {
this.name = name;
this.Mother = Mother;
this.Father = Father;
}
@Override
public String toString() {
if (Father == null && Mother == null)
return "The cat's name is " + name + ", no mother, no father ";
else if(Mother == null)
return "The Cat's name is " + name + ", no mother, father is " + Father.name;
else if (Father == null)
return "The cat's name is " + name + ", mother is " + Mother.name + ", no father ";
else
return "The Cat's name is " + name + ", mother is " + Mother.name +", father is " + Father.name;
}
}
}
Alexander Korznikov
9 уровень
Хоть убейте - не могу понять что не работает. Проверил вдоль и поперек. Кто-то может ткнуть носом в ошибку?
Решен
Комментарии (4)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Дмитрий СоснинExpert
22 декабря 2018, 04:30решение
Вот
+3
Alexander Korznikov
22 декабря 2018, 22:51
Спасибо огромное ! Я бы так сидел и искал бы ошибку. За сервис - отдельное спасибо)
0
Timur
22 декабря 2018, 04:11
во второй и третий else if добавь конкретнее условие типа - если объект отец пустой И объект мать НЕ пустой.
0
Veronika Nikitina
30 декабря 2018, 10:59
не помогает
0