Ввод:
дедушка Вася
бабушка Мурка
папа Котофей
мама Василиса
сын Мурчик
дочь Пушинка
Вывод:
The cat's name is дедушка Вася, no mother, no father
The cat's name is бабушка Мурка, no mother, no father
The cat's name is папа Котофей, no mother, father is дедушка Вася
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 папа Котофей
Process finished with exit code 0
Но следующие условия не выполняються, согласно валидатору:
4. Строка про дедушку (первая) должна соответствовать условию.
5. Строка про бабушку (вторая) должна соответствовать условию.
6. Строка про папу (третья) должна соответствовать условию.
7. Строка про маму (четвертая) должна соответствовать условию.
8. Строка про сына (пятая) должна соответствовать условию.
9. Строка про дочь (шестая) должна соответствовать условию.
package com.javarush.task.task06.task0621;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Родственные связи кошек
*/
public class Solution {
public static int catCount = 0;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fatherName1 = reader.readLine();
Cat father = new Cat(fatherName1);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String sonName1 = reader.readLine();
Cat catDaughter1 = new Cat(sonName1, father);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother);
String grandSonName = reader.readLine();
Cat grandSon = new Cat(grandSonName, catDaughter, catDaughter1);
String granDaughtersName = reader.readLine();
Cat granDaughter = new Cat(granDaughtersName, catDaughter, catDaughter1);
System.out.println(father);
System.out.println(catMother);
System.out.println(catDaughter1);
System.out.println(catDaughter);
System.out.println(grandSon);
System.out.println(granDaughter);
}
public static class Cat {
private String name;
private Cat parent;
private Cat granparent;
int catNumber;
Cat(String name) {
this.name = name;
Solution.catCount++;
catNumber = Solution.catCount;
}
public Cat(String name, Cat parent, Cat granparent) {
this.name = name;
this.parent = parent;
this.granparent = granparent;
Solution.catCount++;
catNumber = Solution.catCount;
}
Cat(String name, Cat parent) {
this.name = name;
this.parent = parent;
Solution.catCount++;
catNumber = Solution.catCount;
}
@Override
public String toString() {
String catsNames="";
if (catNumber==1||catNumber==2)
catsNames = "The cat's name is " + name + ", no mother, no father ";
if (catNumber==3)
catsNames = "The cat's name is " + name + ", no mother, father is " + parent.name;
if (catNumber == 4)
catsNames = "The cat's name is " + name + ", mother is " + parent.name+", no father";
if (catNumber==5||catNumber==6)
catsNames = "The cat's name is " + name + ", mother is " + parent.name+", father is " + granparent.name;
return catsNames;
}
}
}