Добрый день!
Сделал немного иначе реализацию, но работает верно по условию. А валидацию не проходит. Подскажите, пожалуйста, почему?
Пример сравнения первой строчки итд:
The cat's name is дедушка Вася, no mother, no father
The cat's name is дедушка Вася, no mother, no father
Идентично же..
Спасибо!
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 grandfather = reader.readLine();
Cat catGrandfather = new Cat(grandfather);
String grandmother = reader.readLine();
Cat catGrandmother = new Cat(grandmother);
String father = reader.readLine();
Cat catFather = new Cat(father);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName);
String son = reader.readLine();
Cat catSon = new Cat(son);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName);
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 static String grandfather;
private static String grandmother;
private static String father;
private static String motherName;
private static String son;
private static String daughterName;
private static int indexVar = 0;
private static int indexIf = -1;
Cat(String name) {
if (indexVar == 0)
this.grandfather = name;
if (indexVar == 1)
this.grandmother = name;
if (indexVar == 2)
this.father = name;
if (indexVar == 3)
this.motherName = name;
if (indexVar == 4)
this.son = name;
if (indexVar == 5)
this.daughterName = name;
indexVar++;
}
/*
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 папа Котофей
System.out.println(grandfather);
System.out.println(grandmother);
System.out.println(father);
System.out.println(motherName);
System.out.println(son);
System.out.println(daughterName);
*/
@Override
public String toString() {
indexIf++;
if (indexIf == 0)
return "The cat's name is " + grandfather + ", no mother, no father";
if (indexIf == 1)
return "The cat's name is " + grandmother + ", no mother, no father";
if (indexIf == 2)
return "The cat's name is " + father + ", no mother, father is " + grandfather;
if (indexIf == 3)
return "The cat's name is " + motherName + ", mother is " + grandmother + ", no father";
if (indexIf == 4)
return "The cat's name is " + son + ", mother is " +motherName + ", father is " + father;
if (indexIf == 5)
return "The cat's name is " + daughterName + ", mother is " + motherName + ", father is " + father;
return "error";
}
}
}