public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String dadfatherName = reader.readLine();
Cat catDadfather = new Cat(dadfatherName);
String grandmotherName = reader.readLine();
Cat catGrandmother = new Cat(grandmotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, catGrandmother, catDadfather);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catGrandmother, catDadfather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catFather);
String catsunName = reader.readLine();
Cat catSun = new Cat(catsunName, catMother, catFather);
System.out.println(catDadfather);
System.out.println(catGrandmother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSun);
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 parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null & parent1 == null)
return "Cat name is " + name + ", no mother, " + "no father";
if (parent1 == null)
return "Cat name is " + name + ", no mother, " + "father is" + parent2.name;
if (parent2 == null)
return "Cat name is " + name + ", mother is " + parent1.name + "no father";
else
return "Cat name is " + name + ", mother is " + parent1.name + ", father is" + parent2.name;
}
}
помогите плиз. чет уже уплыл. пишет что с третей строки и дальше не правильно. но компиляцию проходит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 dadfatherName = reader.readLine();
Cat catDadfather = new Cat(dadfatherName);
String grandmotherName = reader.readLine();
Cat catGrandmother = new Cat(grandmotherName);
String fatherName = reader.readLine();
Cat catFather = new Cat(fatherName, catGrandmother, catDadfather);
String motherName = reader.readLine();
Cat catMother = new Cat(motherName, catGrandmother, catDadfather);
String daughterName = reader.readLine();
Cat catDaughter = new Cat(daughterName, catMother, catFather);
String catsunName = reader.readLine();
Cat catSun = new Cat(catsunName, catMother, catFather);
System.out.println(catDadfather);
System.out.println(catGrandmother);
System.out.println(catFather);
System.out.println(catMother);
System.out.println(catSun);
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 parent1, Cat parent2) {
this.name = name;
this.parent1 = parent1;
this.parent2 = parent2;
}
@Override
public String toString() {
if (parent1 == null & parent1 == null)
return "Cat name is " + name + ", no mother, " + "no father";
if (parent1 == null)
return "Cat name is " + name + ", no mother, " + "father is" + parent2.name;
if (parent2 == null)
return "Cat name is " + name + ", mother is " + parent1.name + "no father";
else
return "Cat name is " + name + ", mother is " + parent1.name + ", father is" + parent2.name;
}
}
}