Немного не не понимаю... подскажите как разделить парент1 и парент2 ведь конструктору все равно и мы можем вводить любые имена.. как проверить этих дедушек и бабушек и записать их в правильную переменную?
Строка про папу (третья) должна соответствовать условию.
Строка про сына (пятая) должна соответствовать условию.
Строка про дочь (шестая) должна соответствовать условию.
К стати две проблемы, строка третья я про нее спрашиваю выше... сейчас заметил что строка 5 и 6 не соответствуют условию... но почему...
The cat's name is дедушка Вася, no mother, no father
The cat's name is бабушка Мурка, no mother, no father
The cat's name is папа Котофей, mother is дедушка Вася, no father
The cat's name is мама Василиса, mother is бабушка Мурка, no father
The cat's name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
The cat's name is сын Мурчик, mother is мама Василиса, father is папа Котофей
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 catGrandFather = new Cat(grandFatherName);
String grandMotherName = reader.readLine();
Cat catGrandMother = new Cat(grandMotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, catGrandFather);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catGrandMother);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catFather);
String sonName = reader.readLine();
Cat catSon = new Cat(sonName, catFather, catMother);
System.out.println(catGrandFather);
System.out.println(catGrandMother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSon);
System.out.println(catDaughter);
}
public static class Cat {
private String name;
private Cat parent1;
private Cat parent2;
Cat(String name) {
this.name = name;
}
Cat(String name, Cat parent) {
this.name = name;
this.parent1 = parent;
}
Cat(String name, Cat parent1, Cat parent2){
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null && parent2 == null)
{return "The cat's name is " + name + ", no mother, no father";}
else if (parent2 == null)
{return "The cat's name is " + name + ", mother is " + parent1.name + ", no father";}
/* else if (parent1 == null)
{return "The cat's name is " + name + ", no mather, father is" + parent2.name;} */
else
return "The cat's name is " + name + ", mother is " + parent1.name + ", father is, " + parent2.name;
}
}
}